Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int switchPin = 8;
- unsigned long previousTime = 0;
- int switchState = 0;
- int previousSwitchState = 0;
- const int ledSetup[] = {2,3,4,5,6,7};
- int led = 2;
- long interval= 1000;
- void setup()
- {
- Serial.begin(9600);
- for(int x = 0; x<6;x++)
- {
- pinMode(ledSetup[x],OUTPUT);
- }
- pinMode(switchPin, INPUT);
- }
- void loop()
- {
- unsigned long currentTime = millis();
- if(currentTime - previousTime > interval)
- {
- previousTime = currentTime;
- //Serial.println("a led turned on");
- digitalWrite(led,HIGH);
- led++;
- }
- switchState = digitalRead(switchPin);
- if(switchState != previousSwitchState)
- {
- Serial.println("it tilted");
- for(int x = 5;x > 0;x--)
- {
- digitalWrite(ledSetup[x],LOW);
- delay(interval);
- }
- led = 2;
- previousTime = currentTime;
- }
- previousSwitchState = switchState;
- }
Advertisement
Add Comment
Please, Sign In to add comment