1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
int leds[]={6,7,8,9,10,11,12,13}; int btnStart=5; int btnStop=4; int states=1; int num=0; unsigned long cnt=0; void setup() { for (int i=0;i<8;i++) { pinMode(leds[i], OUTPUT); } pinMode(btnStart, INPUT); pinMode(btnStop, INPUT); } void loop() { if (digitalRead(btnStart)) { states=1; } else if (digitalRead(btnStop)) { states=0; } if (states) { if (millis() > cnt+200) { num++; cnt=millis(); } if (num > 7) { num=0; } digitalWrite(leds[num], HIGH); digitalWrite(leds[(num+7)%8], LOW); } } |