Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Britney Beatey
- * Version 2
- * Dice Prototype
- */
- const int pinLed1 = 7;
- const int pinLed2 = 5;
- const int pinLed3 = 3;
- const int pinButt = 10;
- boolean buttDown = 0;
- boolean ledOn = 0;
- boolean lastButt = 0;
- int counter = 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:
- buttDown = debounce(lastButt); // will go and read the Button
- if (lastButt == LOW && buttDown == HIGH) // Checks if the button has been pressed
- {
- counter = counter + 1;
- Serial.println(counter);
- }
- 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;
- }
- lastButt = buttDown;
- }
- boolean debounce(boolean last)
- {
- boolean current = digitalRead(pinButt);
- if (last != current)
- {
- delay(5);
- current = digitalRead(pinButt);
- }
- return current;
- }
Add Comment
Please, Sign In to add comment