Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int buttons[] = {2,3,4};
- int buttonState = 0;
- int currentButton = 0;
- float timer = 0;
- int score = 0;
- int gameState = 0;
- int pinState = 0;
- int currentPin = 0;
- int allPins[] = {2,3,4,5,6,7,8,9,10,11,12,13};
- void setup() {
- Serial.begin(9600);
- pinMode(13, OUTPUT);
- pinMode(12, OUTPUT);
- pinMode(11, OUTPUT);
- pinMode(4, INPUT);
- pinMode(3, INPUT);
- pinMode(2, INPUT);
- gameState = 1;
- currentButton = random(2,5);
- }
- void buttonSelect() {
- currentButton = random(2,5);
- }
- void buttonCheck() {
- buttonState = digitalRead(currentButton);
- if (buttonState == HIGH && gameState == 1) {
- //pinState = HIGH;
- score += 1;
- digitalWrite(currentPin, LOW);
- buttonSelect();
- delay(500);
- } else {
- //pinState = LOW;
- }
- }
- void buttonToPin () {
- if (currentButton == 2) {
- currentPin = 13;
- }
- if (currentButton == 3) {
- currentPin = 12;
- }
- if (currentButton == 4) {
- currentPin = 11;
- }
- }
- void loop() {
- if(timer >= 60) {
- timer = 0;
- //gameState = 0;
- } else {
- timer += 0.01;
- }
- buttonCheck();
- buttonToPin();
- digitalWrite(currentPin, HIGH);
- Serial.println(currentPin);
- Serial.println(currentButton);
- Serial.println(score);
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement