Hello everyone !
I started to learn how Arduino works some weeks ago and I'm stuck in the writing of my program. I have six LEDs and six push buttons for each of them. My goal is that a LED lights up randomly and when you press the push button associated with this LED, it turns off. Then, when you stop holding the press button another LED lights up randomly as well. Then, you press the push button associated with the LED and it turns off. Then, when we stop holding the puss button, another LED lights up randomly and so on. I need this kind of program to create targets for trainings of karate. When a LED turn on randomly, you press the button and then this one will turn off and a new one will turn on. The program I have right now can turn on a LED randomly but when we press the push button, we need to press it for at least five seconds (because this is the delay I put) before it changes of LED but it needs to change right when we press the push button. Can someone help me please ?
PS : English is not my mother tongue so maybe some mistakes are in this text
Thank you !
Here's my program :
int randomNumber;
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
Serial.println("Start a new sequence of Random Number");
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);
pinMode (11, OUTPUT);
pinMode (12, OUTPUT);
pinMode (13, OUTPUT);
pinMode (7, INPUT_PULLUP);
randomSeed( analogRead(0) );
}
void loop() {
// put your main code here, to run repeatedly:
int n = 1;
int k = 5;
int a = 5;
for(n = 1; n < 2; n++)
{
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
digitalWrite (10, HIGH);
digitalWrite (11, HIGH);
digitalWrite (12, HIGH);
digitalWrite (13, HIGH);
delay(750);
digitalWrite (8, LOW);
digitalWrite (9, LOW);
digitalWrite (10, LOW);
digitalWrite (11, LOW);
digitalWrite (12, LOW);
digitalWrite (13, LOW);
delay(750);
}
while(k == a)
{
randomNumber = random(8,14);
Serial.print("The Random Number is");
Serial.println(randomNumber);
int pusshedA = digitalRead(7);
if(pusshedA == HIGH){
digitalWrite(randomNumber, HIGH);
delay(5000);
}else{
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
}
}
Programme_Audrey_3.ino (1.56 KB)