Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Divya Inaganti
- * June 9, 2017
- * LED Dice Mini Project
- * Branching Version 1
- */
- const int pinLed1 = 2;
- const int pinLed2 = 7;
- const int pinLed3 = 4;
- const int pinButton = 8;
- boolean buttonDown = 0;
- boolean ledOn = 0;
- boolean lastButton = 0;
- int counter = 0;
- void setup() {
- // put your setup code here, to run once:
- pinMode (pinLed1, OUTPUT);
- pinMode (pinLed2, OUTPUT);
- pinMode (pinLed3, OUTPUT);
- pinMode (pinButton, INPUT);
- Serial. begin (9600);
- digitalWrite (pinLed1, HIGH);
- digitalWrite (pinLed2, HIGH);
- digitalWrite (pinLed3, HIGH);
- delay(500);
- digitalWrite (pinLed1, LOW);
- digitalWrite (pinLed2, LOW);
- digitalWrite (pinLed3, LOW);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- buttonDown = digitalRead(pinButton);
- //Serial.print (buttonDown);
- buttonDown = debounce(lastButton); // will go and read the Button
- if (lastButton == LOW && buttonDown == HIGH) // Checks if the button has been pressed
- {
- counter = counter + 1;
- }
- // else if(lastButton == HIGH && buttonDown == LOW)
- //{
- //Serial.print (0);
- //}
- if (counter == 1)
- {
- digitalWrite(pinLed1, HIGH);
- digitalWrite(pinLed2, LOW);
- digitalWrite(pinLed3, LOW);
- }
- else if (counter == 2)
- {
- digitalWrite(pinLed1, HIGH);
- digitalWrite(pinLed2, HIGH);
- digitalWrite(pinLed3, LOW);
- }
- else if (counter ==3)
- {
- digitalWrite(pinLed1, HIGH);
- digitalWrite(pinLed2, HIGH);
- digitalWrite(pinLed3, HIGH);
- }
- else
- {
- digitalWrite(pinLed1, LOW);
- digitalWrite(pinLed2, LOW);
- digitalWrite(pinLed3, LOW);
- counter = 0;
- }
- lastButton = buttonDown;
- }
- boolean debounce(boolean last)
- {
- boolean current = digitalRead(pinButton);
- if (last != current)
- {
- delay(5);
- current = digitalRead(pinButton);
- }
- return current;
- }
Add Comment
Please, Sign In to add comment