Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int buttonPin = 2;
- int current = 0;
- long lastEventMillis = 0;
- void setup() {
- pinMode(6, OUTPUT);
- pinMode(7, OUTPUT);
- pinMode(8, OUTPUT);
- pinMode(9, OUTPUT);
- pinMode (buttonPin, INPUT);
- }
- void loop() {
- long currentMillis = millis();
- // This is only true once every 1 second
- if ((currentMillis - previousMillis) > 1000)
- {
- // Apply when last event toke place
- lastEventMillis = currentMillis;
- update();
- }
- // When the button is pressed
- if (digitalRead(buttonPin) == HIGH)
- {
- // Apply when last event toke place
- lastEventMillis = currentMillis;
- // Reset current position
- current = 0;
- update();
- }
- }
- // Updates the position of the LEDs in order
- void update() {
- // Turn all LEDs off
- digitalWrite(6, LOW);
- digitalWrite(7, LOW);
- digitalWrite(8, LOW);
- digitalWrite(9, LOW);
- // Enable the LED that matches the current position
- digitalWrite ((current % 4) + 6, LOW);
- // Update the current position
- current = current + 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement