Hi, I'm kinda new to this stuff, doing it for a design project
Basically i have this set-up as pictured below, and am trying to get the LED's to light up randomly, then stay on for a given amount of time, then be turned off by its corresponding push-button. I also want to be to record if the button isnt pushed in the given time, and if the 'player/participant' fails 3 times, then its game-over.
So far i have this fairly simple code, and just need to try and advance it;
//BUTTON's
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 1; // the number of the pushbutton pin
const int buttonPin2 = 2;
const int buttonPin3 = 3;
//all 3 buttons together
const int maxbuttonpins = 3;
int buttonpin[maxbuttonpins] ;
//LED'S
const int REDLEDPIN1 = 11; // the number of the LED pin
const int REDLEDPIN2 = 12;
const int REDLEDPIN3 = 13;
//all 3 LEDs together
const int maxLedPins = 3;
int ledpins[maxLedPins] = {REDLEDPIN1, REDLEDPIN2, REDLEDPIN3};
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(REDLEDPIN1, OUTPUT);
pinMode(REDLEDPIN2, OUTPUT);
pinMode(REDLEDPIN3, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin1);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(REDLEDPIN1, LOW);
digitalWrite(REDLEDPIN2, LOW);
digitalWrite(REDLEDPIN3, LOW);
}
else {
// KEEP LED ON:
digitalWrite(REDLEDPIN1, HIGH);
digitalWrite(REDLEDPIN2, LOW);
digitalWrite(REDLEDPIN3, LOW);
}
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin2);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(REDLEDPIN1, LOW);
digitalWrite(REDLEDPIN2, LOW);
digitalWrite(REDLEDPIN3, LOW);
}
else {
// KEEP LED ON:
digitalWrite(REDLEDPIN1, LOW);
digitalWrite(REDLEDPIN2, HIGH);
digitalWrite(REDLEDPIN3, LOW);
}
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin3);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(REDLEDPIN1, LOW);
digitalWrite(REDLEDPIN2, LOW);
digitalWrite(REDLEDPIN3, LOW);
}
else {
// KEEP LED ON:
digitalWrite(REDLEDPIN1, LOW);
digitalWrite(REDLEDPIN2, LOW);
digitalWrite(REDLEDPIN3, HIGH);
}
}
Any help would be thoroughly appreciated
O'm