Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int LedPinGreen = 11;
- const int LedPinRed = 10;
- const int Button = 12;
- boolean ReadValue;
- boolean LastValue;
- int counter=0;
- void setup()
- {
- pinMode (LedPinGreen, OUTPUT);
- pinMode (LedPinRed, OUTPUT);
- pinMode (Button, INPUT);
- Serial.begin (9600);
- }
- boolean debounce(boolean last)
- {
- boolean current = digitalRead(Button);
- if (last != current)
- {
- delay(5);
- current = digitalRead(Button);
- }
- return current;
- }
- void loop()
- {
- ReadValue = debounce (LastValue);
- if (LastValue == LOW && ReadValue ==HIGH)
- {
- counter++;
- Serial.println(counter);
- }
- if (counter== 1||counter == 4)
- {
- digitalWrite (LedPinRed, HIGH);
- digitalWrite (LedPinGreen, LOW);
- }
- if (counter==2)
- {digitalWrite (LedPinRed, LOW);
- digitalWrite (LedPinGreen, HIGH);
- }
- if (counter == 3)
- {
- digitalWrite (LedPinRed, HIGH);
- digitalWrite (LedPinGreen, HIGH);
- }
- if (counter == 5)
- {
- digitalWrite (LedPinRed, LOW);
- digitalWrite (LedPinGreen, LOW);
- counter=0;
- }
- LastValue = ReadValue;
- }
Add Comment
Please, Sign In to add comment