Hello Forum, this is my first Arduino project not from a book and I am running into some trouble. My goal is to make an led system like a simplified version of the one on the game Jeopardy in which when a force sensor is pushed, its corresponding led lights up and then after 4 seconds the red led lights up indicating that time has run out. When one sensor is pushed, it shouldn't let the other led come on. The problem is in the time between when the sensor is pressed and when its led turns on. It seems to take a while to light up, or it won't light up at all.
Here's the code and thanks!
//Building a Jeopardy! Buzzer System with LEDs
//If one sensor is pressed its LED lights up and blocks the other
//After 4 seconds the red LED turns on
int sensorAPin = 1;
int sensorBPin = 2;
int ledAPin = 10;
int ledBPin = 9;
int ledCPin = 11;
int val=0;
int val2=0;
void setup(){
pinMode (ledAPin, OUTPUT); //LED is an OUTPUT
pinMode (ledBPin, OUTPUT); //LED is an OUTPUT
pinMode (ledCPin, OUTPUT); //LED is an OUTPUT
}
void loop(){
val = analogRead (sensorAPin);
val2 = analogRead (sensorBPin);
if (val>500 && val2<500){
digitalWrite (ledAPin,HIGH);
digitalWrite (ledBPin,LOW);
delay(4000);
digitalWrite (ledCPin, HIGH);
}
else if (val<500 && val2>500){
digitalWrite (ledAPin,LOW);
digitalWrite (ledBPin,HIGH);
delay(4000);
digitalWrite (ledCPin, HIGH);
}
}