Informatikunterricht

am Gymnasium Kirchenfeld

Benutzer-Werkzeuge

Webseiten-Werkzeuge


digitalelektronik:moving-light

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
digitalelektronik:moving-light [2015/02/12 08:27] rosdigitalelektronik:moving-light [2020/10/13 14:25] (aktuell) – Externe Bearbeitung 127.0.0.1
Zeile 9: Zeile 9:
 <code c++> <code c++>
 const int DELAY_MS = 500; const int DELAY_MS = 500;
-const int PIN[] = { 2, 3, 4, 5, 6, 7, 8, 9 }; + 
-const int PIN_COUNT = sizeof(PIN) / sizeof(int);+const int PIN[] = { 2, 3, 4, 5 }; 
 +const int PIN_COUNT = 4; 
 int currentLed; int currentLed;
  
Zeile 26: Zeile 28:
 void loop() { void loop() {
     digitalWrite(PIN[currentLed], LOW);     digitalWrite(PIN[currentLed], LOW);
-    currentLed = (currentLed + 1) % PIN_COUNT;+    currentLed = currentLed + 1
 +    if (PIN_COUNT <= currentLed) { 
 +        currentLed = 0; 
 +    } 
     digitalWrite(PIN[currentLed], HIGH);     digitalWrite(PIN[currentLed], HIGH);
     delay(DELAY_MS);     delay(DELAY_MS);
Zeile 39: Zeile 45:
 const int DELAY_MS = 100; const int DELAY_MS = 100;
 const int PIN[] = { 2, 3, 4, 5, 6, 7, 8, 9 }; const int PIN[] = { 2, 3, 4, 5, 6, 7, 8, 9 };
-const int PIN_COUNT = sizeof(PIN) / sizeof(int);+const int PIN_COUNT = 8; 
 int currentLed; int currentLed;
 int dir; int dir;
Zeile 75: Zeile 82:
 const int DELAY_MS = 100; const int DELAY_MS = 100;
 const int PIN[] = { 2, 3, 4, 5, 6, 7, 8, 9 }; const int PIN[] = { 2, 3, 4, 5, 6, 7, 8, 9 };
-const int PIN_COUNT = sizeof(PIN) / sizeof(int);+const int PIN_COUNT = 8; 
 int currentLed; int currentLed;
 int dir; int dir;
digitalelektronik/moving-light.1423726041.txt.gz · Zuletzt geändert: 2020/10/13 14:25 (Externe Bearbeitung)