Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int x=3; //s2 button
- int y=2; //s1 button
- int led[8]={11,12,13,14,15,16,17,18};
- int s1,s2;
- int j=0;
- void setup()
- {
- pinMode(3, INPUT);
- pinMode(2, INPUT);
- for(int i=0;i<8;i++)
- pinMode(led[i], OUTPUT);
- digitalWrite(led[j],HIGH); // first led will be turned on
- }
- void loop()
- {
- s2 = digitalRead(x); //to right
- s1 = digitalRead(y); //to left
- // if s2 is pressed then it will go right
- if (s2 == HIGH) {
- digitalWrite(led[j],LOW);
- j=j+1;
- if(j>7) //end of the array
- j=7;
- if(j<0) //the other end of the array
- j=2;
- digitalWrite(led[j], HIGH);
- delay(500);
- }
- if (s1 == HIGH) { // if s1 is press then it will go to left
- digitalWrite(led[j],LOW);
- j=j-1;
- if(j>7) //end of the array
- j=0;
- if(j<0) //the other end of the array
- j=0;
- digitalWrite(led[j], HIGH);
- delay(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement