====== Zählen mit einer Siebensegmentanzeige ====== Dieses Programm zählt von 0 bis 9 und stellt die Ziffer auf einer Siebensegmentanzeige dar. Die Siebensegmentanzeige wird wie folgt angeschlossen: ^ Segment ^ Pin ^ Bit ^ | a | 8 | 6 | | b | 7 | 5 | | c | 6 | 4 | | d | 5 | 3 | | e | 4 | 2 | | f | 3 | 1 | | g | 2 | 0 | const int DELAY_MS = 1000; const int SEGMENT_PIN[] = { 8, 7, 6, 5, 4, 3, 2 }; const int SEGMENT_PIN_COUNT = 7; const byte DIGIT[] = { // abcdefg B01111110, // 0 B00110000, // 1 B01101101, // 2 B01111001, // 3 B00110011, // 4 B01011011, // 5 B01011111, // 6 B01110000, // 7 B01111111, // 8 B01111011 // 9 }; const int DIGIT_COUNT = 10; byte number; void setup() { int i = 0; while (i < SEGMENT_PIN_COUNT) { pinMode(SEGMENT_PIN[i], OUTPUT); i = i + 1; } number = 0; } void showByte(byte b) { byte i = 0; while (i < SEGMENT_PIN_COUNT) { if ((b & (1 << i)) != 0) { digitalWrite(SEGMENT_PIN[i], HIGH); } else { digitalWrite(SEGMENT_PIN[i], LOW); } i = i + 1; } } void loop() { showByte(DIGIT[number]); number = number + 1; if (number >= DIGIT_COUNT) { number = 0; } delay(DELAY_MS); }