Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. int x=3; //s2 button
  2. int y=2; //s1 button
  3. int led[8]={11,12,13,14,15,16,17,18};
  4. int s1,s2;
  5. int j=0;
  6.  
  7.  
  8. void setup()
  9. {
  10. pinMode(3, INPUT);
  11. pinMode(2, INPUT);
  12. for(int i=0;i<8;i++)
  13. pinMode(led[i], OUTPUT);
  14. digitalWrite(led[j],HIGH); // first led will be turned on
  15. }
  16.  
  17.  
  18. void loop()
  19. {
  20. s2 = digitalRead(x); //to right
  21. s1 = digitalRead(y); //to left
  22.  
  23. // if s2 is pressed then it will go right
  24. if (s2 == HIGH) {
  25. digitalWrite(led[j],LOW);
  26. j=j+1;
  27. if(j>7) //end of the array
  28. j=7;
  29. if(j<0) //the other end of the array
  30. j=2;
  31. digitalWrite(led[j], HIGH);
  32. delay(500);
  33. }
  34.  
  35. if (s1 == HIGH) { // if s1 is press then it will go to left
  36. digitalWrite(led[j],LOW);
  37. j=j-1;
  38. if(j>7) //end of the array
  39. j=0;
  40. if(j<0) //the other end of the array
  41. j=0;
  42. digitalWrite(led[j], HIGH);
  43. delay(500);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement