Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Atiriya Iyer
- * Dice Prototype
- * Version 1
- */
- const int pinLED1= 2;
- const int pinLED2= 4;
- const int pinLED3= 6;
- const int pinButton= 5;
- boolean buttonPressed = 0;
- boolean LEDon= 0;
- boolean previousButton=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(50);
- digitalWrite(pinLED1, LOW);
- digitalWrite(pinLED2, LOW);
- digitalWrite(pinLED3, LOW);
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- buttonPressed= digitalRead(pinButton);
- //Serial.print (buttonPressed);
- buttonPressed = debounce(previousButton);
- if (previousButton== LOW && buttonPressed== HIGH)
- {
- LEDon =! LEDon;
- Serial.print(LEDon);
- }
- digitalWrite(pinLED1, LEDon);
- digitalWrite(pinLED2, LEDon);
- digitalWrite(pinLED3, LEDon);
- previousButton= buttonPressed;
- }
- 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