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 btnUp=5; int btnDown=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(btnUp, INPUT); pinMode(btnDown, INPUT); } void loop() { if (digitalRead(btnUp)) { states=1; } else if (digitalRead(btnDown)) { states=-1; } if (millis() > cnt+200) { num+=states; } if (num > 7) { num=0; } else if (num < 0) { num=7; } digitalWrite(leds[num], HIGH); delay(200); digitalWrite(leds[num], LOW); } |