Advertisement
APersonH

ArduinoButtonGameWIP

Sep 8th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. int buttons[] = {2,3,4};
  2. int buttonState = 0;
  3. int currentButton = 0;
  4. float timer = 0;
  5. int score = 0;
  6. int gameState = 0;
  7. int pinState = 0;
  8. int currentPin = 0;
  9. int allPins[] = {2,3,4,5,6,7,8,9,10,11,12,13};
  10.  
  11. void setup() {
  12.   Serial.begin(9600);
  13.   pinMode(13, OUTPUT);
  14.   pinMode(12, OUTPUT);
  15.   pinMode(11, OUTPUT);
  16.   pinMode(4, INPUT);
  17.   pinMode(3, INPUT);
  18.   pinMode(2, INPUT);
  19.   gameState = 1;
  20.   currentButton = random(2,5);
  21. }
  22.  
  23. void buttonSelect() {
  24.     currentButton = random(2,5);
  25.   }
  26.  
  27. void buttonCheck() {
  28.   buttonState = digitalRead(currentButton);
  29.   if (buttonState == HIGH && gameState == 1) {
  30.     //pinState = HIGH;
  31.     score += 1;
  32.     digitalWrite(currentPin, LOW);
  33.     buttonSelect();
  34.     delay(500);
  35.   } else {
  36.     //pinState = LOW;
  37.   }
  38. }
  39.  
  40. void buttonToPin () {
  41.   if (currentButton == 2) {
  42.       currentPin = 13;
  43.     }
  44.   if (currentButton == 3) {
  45.       currentPin = 12;
  46.     }
  47.   if (currentButton == 4) {
  48.       currentPin = 11;
  49.     }
  50.   }
  51.  
  52. void loop() {
  53.   if(timer >= 60) {
  54.       timer = 0;
  55.       //gameState = 0;
  56.     } else {
  57.       timer += 0.01;
  58.       }
  59.   buttonCheck();
  60.   buttonToPin();
  61.   digitalWrite(currentPin, HIGH);
  62.   Serial.println(currentPin);
  63.   Serial.println(currentButton);
  64.   Serial.println(score);
  65.   delay(10);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement