Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Lighting all the LED mini project prototype
- * Rylyn Koger
- * Version 2 06/09/2017
- *
- */
- const int pinBlue=5;
- const int pinWhite=4;
- const int pinRed=3;
- const int pinButton=2;
- int readValue= 0;
- int counter=0;
- int currentState=0;
- int previousState=0;
- boolean flag=0;
- boolean lastButton=0;
- void setup()
- {
- pinMode(pinBlue, OUTPUT);
- pinMode(pinWhite, OUTPUT);
- pinMode(pinRed, OUTPUT);
- pinMode(pinButton, INPUT);
- digitalWrite(pinBlue, HIGH);
- delay(1000);
- digitalWrite(pinWhite, HIGH);
- delay(1000);
- digitalWrite(pinRed, HIGH);
- delay(1000);
- digitalWrite(pinBlue, LOW);
- digitalWrite(pinWhite, LOW);
- digitalWrite(pinRed, LOW);
- Serial.begin(9600);
- }
- void loop()
- //Serial.print(digitalRead(pinButton);
- {
- readValue = digitalRead(pinButton);
- delay (5);
- readValue = debounce(lastButton); // will go and read the Button
- if (lastButton == LOW && readValue == HIGH) // Checks if the button has been pressed
- {
- counter ++;
- }
- if(counter==1)
- {
- digitalWrite (pinBlue, HIGH);
- digitalWrite (pinWhite, LOW);
- digitalWrite (pinRed, LOW);
- }
- else if(counter==2)
- {
- digitalWrite(pinBlue, LOW);
- digitalWrite(pinWhite, HIGH);
- digitalWrite(pinRed, LOW);
- }
- else if (counter==3)
- {
- digitalWrite(pinBlue, LOW);
- digitalWrite(pinWhite, LOW);
- digitalWrite(pinRed, HIGH);
- }
- else
- {
- digitalWrite(pinBlue, LOW);
- digitalWrite(pinWhite, LOW);
- digitalWrite(pinRed, LOW);
- counter= 0;
- }
- lastButton = readValue;
- }
- boolean debounce(boolean last)
- {
- boolean current = digitalRead(pinButton);
- if (last != current)
- {
- delay(5);
- current = digitalRead(pinButton);
- }
- return current;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement