ok so i am working on a guessing game for a school project. its a game based off buttons and sensors which have LED’s that light up. anyway i put it all together and used a max patch to calibrate the light sensors and make sure the buttons work. now heres the problem somewhere in the code i messed up and the LED’s switch when the light adjusts not when the guessers buttons. can anyone identify my problem or point me in the right direction?
thank you
JS
i am running ox 10.10.3 arduino 1.6.8 max 7 and using a spark fun red board.
#define guesserWinPin 2 //green for guesser, red for shooter
#define guesserLosePin 3 //red for guesser, green for shooter
#define guessButt1 4 //sets up pins for buttons
#define guessButt2 5
#define guessButt3 6
#define guessButt4 7
#define sensorThreshold 150 //if sensors are uncovered
#define shooterSensor1 0
#define shooterSensor2 1
#define shooterSensor3 2
#define shooterSensor4 3
void setup() {
pinMode (guessButt1, INPUT); // take out Pullup and wire it with a resistor//
pinMode (guessButt2, INPUT);
pinMode (guessButt3, INPUT);
pinMode (guessButt4, INPUT);
pinMode (guesserWinPin, OUTPUT);
pinMode (guesserLosePin, OUTPUT);
}
void loop() {
if (digitalRead(guessButt1) == 1)
{
if (analogRead(shooterSensor1) < sensorThreshold) //if it's lower, there's a shotglass on it
{
digitalWrite(guesserWinPin, HIGH);
delay (5000);
digitalWrite(guesserWinPin, LOW);
}
else
{
digitalWrite(guesserLosePin, HIGH);
delay (5000);
digitalWrite(guesserLosePin, LOW);
}
}
if (digitalRead(guessButt2) == 1)
{
if (analogRead(shooterSensor2) < sensorThreshold) //if it's lower, there's a shotglass on it
{
digitalWrite(guesserWinPin, HIGH);
delay (5000);
digitalWrite(guesserWinPin, LOW);
}
else
{
digitalWrite(guesserLosePin, HIGH);
delay (5000);
digitalWrite(guesserLosePin, LOW);
}
}
if (digitalRead(guessButt3) == 1)
{
if (analogRead(shooterSensor3) < sensorThreshold) //if it's lower, there's a shotglass on it
{
digitalWrite(guesserWinPin, HIGH);
delay (5000);
digitalWrite(guesserWinPin, LOW);
}
else
{
digitalWrite(guesserLosePin, HIGH);
delay (5000);
digitalWrite(guesserLosePin, LOW);
}
}
if (digitalRead(guessButt4) == 1)
{
if (analogRead(shooterSensor4) < sensorThreshold) //if it's lower, there's a shotglass on it
{
digitalWrite(guesserWinPin, HIGH);
delay (5000);
digitalWrite(guesserWinPin, LOW);
}
else
{
digitalWrite(guesserLosePin, HIGH);
delay (5000);
digitalWrite(guesserLosePin, LOW);
}
}
}