Hi, i'm having some problem programming the arduino.
So this is how i want it to work: You turn it on, a time passes, then a led turns on, you push the button and a lcd shows you how long you were pressing the button.
Now the problem is that i want it to turn on on a random time, from like 3 seconds to 12 seconds. Any help would be great
I am a beginner with Arduino so take this with a grain of salt, but you could try this:
void setup() {
readyToStart = true;
}
void loop() {
if(readyToStart) { //Ready to turn the light on
readyToStart = false;
delay(random(3000, 12000)); //Delay a random number of seconds
digitalWrite(LEDPIN, HIGH);
}
}
Note that this is just an idea. There is probably a better way to do this.
const int buttonPin = 6; // Digital pin that button is connected
const int ledPin1 = 4; // Digital pin that the second led is connected
const int ledPin = 5; // Digital pin that Led is connected
// variables will change:
int buttonState = 0; // variable for the button
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin); // Reading the button
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
digitalWrite(ledPin, HIGH); // The led1 is on
if (buttonState == HIGH) { // if pushed then:
// turn LED on:
delay(random(3000, 12000)); // random time
digitalWrite(ledPin, LOW); // the led1 is off
digitalWrite(ledPin1, HIGH); // the led2 is on
delay (2000); // delay so you can see the light
digitalWrite(ledPin1, LOW); // off
}
else {
// turn LED off:
digitalWrite(ledPin, LOW); // if not pushed
digitalWrite(ledPin1, LOW); // -II-
}
}
now i was wondering how i would count the seconds it takes for you to push, and display it on the serial monitor or even on a lcd