Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Divya Inaganti
- * June 9, 2017
- * LED Dice Prototype version 2
- */
- 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;
- 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
- {
- ledOn = ! ledOn;
- }
- // else if(lastButton == HIGH && buttonDown == LOW)
- //{
- //Serial.print (0);
- //}
- digitalWrite(pinLed1, ledOn);
- lastButton = buttonDown;
- }
- 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