====== Einzelne LEDs ein-/ausschalten ====== ===== main.c ===== /* * Einfaches Demo-Programm * Blinkenlights-Bausatz * www.eHaJo.de * * (C) Hannes Jochriem, 2013 * */ #include #include #include #include int main() { printf("Starte LEDMatrix-Programm\n"); int fd; struct termios options; char buffer; int temp; fd = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY); // seriellen port oeffnen if(fd == -1) { printf("konnte Port nicht oeffnen\n"); } else { fcntl(fd, F_SETFL, 0); printf("port geoeffnet...\n"); } // seriellen port konfigurieren: tcgetattr(fd, &options); cfsetispeed(&options, B115200); cfsetospeed(&options, B115200); options.c_cflag |= (CLOCAL | CREAD); options.c_cflag &= ~PARENB; options.c_cflag &= ~CSTOPB; options.c_cflag &= ~CSIZE; options.c_cflag |= CS8; options.c_cflag &= ~( ICANON | ECHO | ECHOE |ISIG ); options.c_iflag &= ~(IXON | IXOFF | IXANY ); options.c_oflag &= ~OPOST; tcsetattr(fd, TCSANOW, &options); // die config an den port uebertragen while(1) { // haupt-endlosschleife while(1) { printf("Bitte Zeile eingeben (1-8): "); scanf("%d", &temp); if(!(temp < 1 || temp > 8)) { // zeichen gueltig buffer = ((temp-1) << 1); break; } } while(1) { printf("Bitte Spalte eingeben (1-8): "); scanf("%d", &temp); if(!(temp < 1 || temp > 8)) { // zeichen gueltig buffer |= ((temp-1) << 4); break; } } while(1) { printf("Ein (1) oder Aus (0): "); scanf("%d", &temp); if(!(temp < 0 || temp > 1)) { // zeichen gueltig buffer |= temp; break; } } write(fd, &buffer, 1); // sende byte an ledmatrix } close(fd); // port schliessen return 0; }