daniel_lawson9999

Daniel Lawson Hourglass

Oct 20th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. const int switchPin = 8;
  2. unsigned long previousTime = 0;
  3. int switchState = 0;
  4. int previousSwitchState = 0;
  5. const int ledSetup[] = {2,3,4,5,6,7};
  6. int led = 2;
  7. long interval= 1000;
  8.  
  9.  
  10.  
  11.  
  12. void setup()
  13. {
  14. Serial.begin(9600);
  15. for(int x = 0; x<6;x++)
  16. {
  17. pinMode(ledSetup[x],OUTPUT);
  18. }
  19. pinMode(switchPin, INPUT);
  20. }
  21.  
  22. void loop()
  23. {
  24. unsigned long currentTime = millis();
  25. if(currentTime - previousTime > interval)
  26. {
  27. previousTime = currentTime;
  28. //Serial.println("a led turned on");
  29. digitalWrite(led,HIGH);
  30. led++;
  31.  
  32.  
  33. }
  34.  
  35.  
  36.  
  37. switchState = digitalRead(switchPin);
  38.  
  39. if(switchState != previousSwitchState)
  40. {
  41. Serial.println("it tilted");
  42. for(int x = 5;x > 0;x--)
  43. {
  44. digitalWrite(ledSetup[x],LOW);
  45. delay(interval);
  46. }
  47. led = 2;
  48. previousTime = currentTime;
  49. }
  50. previousSwitchState = switchState;
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment