Purpose: Flash 4 leds from right to left and left to light. Difficulty / Time to complete: Beginner / 5 minutes Tools:
Arduino board (tested on duemilanove)
4 LEDs
1 switch
1 10K/.25W resistor
Workstation with Arduino 0.017 or higher
Arduino code:
int leds[]={10,11,12,13}; //pins with leds const int dl = 75; //delay between moving const int btn = 9; //button pin int btnS = 0; //button state int i=0; //general purpose counter
//myflash function: flash an array of pins to the R or L void myflash(int arr[],int size,int delay1,boolean reverse){ int j = 0; if(reverse==true){ for(j=(size-1);j>=0;j--){ digitalWrite(arr[j],HIGH); delay(delay1); digitalWrite(arr[j],LOW); } } else { for(j=0;jdigitalWrite(arr[j],HIGH); delay(delay1); digitalWrite(arr[j],LOW); } } }
Note: After copying-pasting code to the Arduino IDE, press Ctrl+T to fix indents.