Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Matt Vawrinek
- * 6/09/17
- * Dice Mini Project
- */
- const int pinLed1 = 2;
- const int pinLed2 = 3;
- const int pinLed3 = 4;
- const int pinButt = 5;
- boolean buttPressed = 0; //this is to tell whether the button is pressed//
- boolean ledOn = 0; //this is for the LED//
- boolean prevButt = 0;
- int counter = 0; //keeping track of how many times you press the button//
- void setup()
- {
- 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 = debounce(prevButt);
- if (prevButt == LOW && buttPressed == HIGH)
- {
- counter++; //++ means add one//
- }
- switch(counter)
- {
- case 1:
- digitalWrite(pinLed1, HIGH);
- digitalWrite(pinLed2, LOW);
- digitalWrite(pinLed3, LOW);
- //do something//
- break;
- case 2:
- digitalWrite(pinLed1, HIGH);
- digitalWrite(pinLed2, HIGH);
- digitalWrite(pinLed3, LOW);
- //do something else//
- break;
- case 3:
- digitalWrite(pinLed1, HIGH);
- digitalWrite(pinLed2, HIGH);
- digitalWrite(pinLed3, HIGH);
- break;
- case 4:
- digitalWrite(pinLed1, LOW);
- digitalWrite(pinLed2, LOW);
- digitalWrite(pinLed3, LOW);
- counter = 0;
- break;
- }
- prevButt = buttPressed; //compare end with start, new value becomes the old value//
- }
- boolean debounce(boolean last)
- {
- boolean current = digitalRead(pinButt);
- if (last != current) // != means not equal to//
- {
- delay(5);
- current = digitalRead(pinButt);
- }
- return current;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement