digitalelektronik:seven-segment-count
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| digitalelektronik:seven-segment-count [2015/03/05 09:12] – ros | digitalelektronik:seven-segment-count [2020/10/13 14:25] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
|---|---|---|---|
| Zeile 16: | Zeile 16: | ||
| <code c++> | <code c++> | ||
| const int DELAY_MS = 1000; | const int DELAY_MS = 1000; | ||
| - | const int PIN[] = { 9, 8, 7, 6, 5, 4, 3, 2 }; | + | const int SEGMENT_PIN[] = { 8, 7, 6, 5, 4, 3, 2 }; |
| - | const int PIN_COUNT | + | const int SEGMENT_PIN_COUNT |
| const byte DIGIT[] = { | const byte DIGIT[] = { | ||
| // abcdefg | // abcdefg | ||
| Zeile 31: | Zeile 31: | ||
| B01111011 | B01111011 | ||
| }; | }; | ||
| + | const int DIGIT_COUNT = 10; | ||
| byte number; | byte number; | ||
| Zeile 36: | Zeile 37: | ||
| void setup() { | void setup() { | ||
| int i = 0; | int i = 0; | ||
| - | while (i < PIN_COUNT) { | + | while (i < SEGMENT_PIN_COUNT) { |
| - | pinMode(PIN[i], OUTPUT); | + | pinMode(SEGMENT_PIN[i], OUTPUT); |
| i = i + 1; | i = i + 1; | ||
| } | } | ||
| Zeile 46: | Zeile 47: | ||
| void showByte(byte b) { | void showByte(byte b) { | ||
| byte i = 0; | byte i = 0; | ||
| - | | + | while (i < SEGMENT_PIN_COUNT) { |
| - | | + | if ((b & (1 << i)) != 0) { |
| - | if ((b & mask) != 0) { | + | digitalWrite(SEGMENT_PIN[i], HIGH); |
| - | digitalWrite(PIN[i], HIGH); | + | |
| } | } | ||
| else { | else { | ||
| - | digitalWrite(PIN[i], LOW); | + | digitalWrite(SEGMENT_PIN[i], LOW); |
| } | } | ||
| i = i + 1; | i = i + 1; | ||
| - | mask = mask << 1; | ||
| } | } | ||
| } | } | ||
| Zeile 62: | Zeile 61: | ||
| void loop() { | void loop() { | ||
| showByte(DIGIT[number]); | showByte(DIGIT[number]); | ||
| - | number = (number + 1) % 10; | + | number = number + 1; |
| + | if (number >= DIGIT_COUNT) { | ||
| + | number = 0; | ||
| + | } | ||
| delay(DELAY_MS); | delay(DELAY_MS); | ||
| } | } | ||
| </ | </ | ||
digitalelektronik/seven-segment-count.1425543127.txt.gz · Zuletzt geändert: 2020/10/13 14:25 (Externe Bearbeitung)