Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Manvi Mittal
- * Dice Prototype
- */
- const int pinLed1 = 2;
- const int pinLed2 = 3;
- const int pinLed3 = 4;
- const int pinButt = 5;
- boolean buttPressed = 0;
- boolean ledOn = 0;
- boolean prevButt = 0;
- void setup()
- {
- // put your setup code here, to run once:
- pinMode (pinLed1, OUTPUT);
- pinMode (pinLed2, OUTPUT);
- pinMode (pinLed3, OUTPUT);
- pinMode (pinButt, 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:
- buttPressed = digitalRead (pinButt);
- //Serial.print (buttPressed);
- buttPressed = debounce (prevButt);
- if (prevButt == LOW && buttPressed == HIGH)
- {
- ledOn = !ledOn;
- Serial.print (ledOn);
- }
- digitalWrite (pinLed1, ledOn);
- digitalWrite (pinLed2, ledOn);
- digitalWrite (pinLed3, ledOn);
- prevButt = buttPressed;
- }
- boolean debounce(boolean last)
- {
- boolean current = digitalRead(pinButt);
- if (last != current)
- {
- delay(5);
- current = digitalRead(pinButt);
- }
- return current;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement