I'm having problems with a ir remote setup the remote is working but any button on the remote will start my count down. am i over looking something or what can i do. Thanks for any help in advance.
// Dual stop watch with state machine
// output on serial monitor
// blinking led while running
#include <LiquidCrystal.h>
#include <IRremote.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
const byte startPin = 8;
const byte stopRightPin = 9;
const byte stopLeftPin = 10;
const byte ledPin = 13;
int irstartPin = 12;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
boolean buttonStartState = HIGH;
boolean buttonStopLeftState = HIGH;
boolean buttonStopRightState = HIGH;
boolean leftIsIn = false;
boolean rightIsIn = false;
byte state = 0; // state machine states: 0 ... 3
unsigned long startTime;
unsigned long stopLeft;
unsigned long stopRight;
unsigned long raceTimeLeft;
unsigned long raceTimeRight;
void setup()
{
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Left");
lcd.setCursor(11, 0);
lcd.print("Right");
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(startPin, INPUT_PULLUP);
pinMode(stopLeftPin, INPUT_PULLUP);
pinMode(stopRightPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(irstartPin, OUTPUT);
}
void loop() {
digitalWrite(irstartPin, HIGH);
if (irrecv.decode(&results))
{
if (results.value == 0xFF22DD);
{
digitalWrite(irstartPin, LOW);
}
irrecv.resume();
}
// read input pins:
buttonStartState = digitalRead(startPin);
buttonStopLeftState = digitalRead(stopLeftPin);
buttonStopRightState = digitalRead(stopRightPin);
switch (state) {
case 0: // make ready for start
Serial.println("press start button");
state++;
break;
case 1: // waiting for start button press
if (buttonStartState == LOW)
{
Serial.println("START");
delay(5000);
startTime = millis();
state++;
}
break;
case 2: // running - waiting for left and/or right stop button press
digitalWrite(ledPin, millis() / 128 % 2); // blink the led
if ( (buttonStopLeftState == LOW) && (leftIsIn == false) ) {
stopLeft = millis();
raceTimeLeft = (stopLeft - startTime);
Serial.print("Left is in: ");
Serial.println(raceTimeLeft / 1000.0, 2);
lcd.setCursor(0, 1);
lcd.print(raceTimeLeft / 1000.0, 2);
leftIsIn = true;
}
if ( (buttonStopRightState == LOW) && (rightIsIn == false) ) {
stopRight = millis();
raceTimeRight = (stopRight - startTime);
Serial.print("Right is in: ");
Serial.println(raceTimeRight / 1000.0, 2);
lcd.setCursor(12, 1);
lcd.print(raceTimeRight / 1000.0, 2);
rightIsIn = true;
}
if ( (leftIsIn == true) && (rightIsIn == true) ) {
digitalWrite(ledPin, LOW);
leftIsIn = false;
rightIsIn = false;
state++;
}
break;
case 3: // print the winner
if (raceTimeLeft < raceTimeRight) {
Serial.println("LEFT WIN");
lcd.setCursor(6, 2);
lcd.print("<---");
}
else {
Serial.println("RIGHT WIN");
lcd.setCursor(6, 2);
lcd.print("--->");
}
state = 0;
break;
}
}[code][code]
[/code][/code]