Here is the situation:
3 buttons(a,b,c)
3 leds(1,2,3)
leds random high,
if a&1 high, 1 keeps high for a while(stop random),
if b&2 high, 2 keeps high for a while(stop random),
if c&3 high, 3 keeps high for a while(stop random)
Question is:
how can I press the button once but not hold down to make this work.
const int ledPin1= 7;
const int ledPin2= 8;
const int ledPin3= 9;
const int butPin1= 4;
const int butPin2= 5;
const int butPin3= 6;
int butState1 = 0;
int butState2 = 0;
int butState3 = 0;
int valueRand;
int vetor[]={ledPin1, ledPin2, ledPin3};
int potValue;
void setup(){
Serial.begin(2400);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(butPin1, INPUT);
pinMode(butPin2, INPUT);
pinMode(butPin3, INPUT);
}
void loop(){
potValue=800;
valueRand =random(0,3);
butState1 = digitalRead(butPin1);
butState2 = digitalRead(butPin2);
butState3 = digitalRead(butPin3);
if((valueRand==0) && (butState1==HIGH)){
potValue=4000;
}else
if((valueRand==1) && (butState2==HIGH)){
potValue=4000;
}else
if((valueRand==2)&& (butState3==HIGH)){
potValue=4000;
}
digitalWrite(vetor[valueRand],HIGH);
delay(potValue);
digitalWrite(vetor[valueRand],LOW);
Serial.print(butState1);
Serial.println(potValue);
}