Hey all, bare with me please. I am fairly new to this and just hit a wall and can't seem to break through it using Google. A little project background first. I am an RC fanatic. I built the RiCino receiver and transponders using Arduino and had huge fun doing so. Since then I have made a few smaller projects trying to get more familiar with the code side of things. I am great with the electronics side of things and not so much with the code.
Each one of our RC trucks is sending a specific modulated IR code per vehicle. I am trying to use the current IR sensor bridge I built for our lap timing system and make it display MPH, lap count, and eventually lap times per vehicle on a large segment display I built. I started basic on this. I currently have the MPH laser break beam sensor figured out and working for the first three digits. The next step is to make the IR system operate a lap counter. To start things slow, I wrote a simple code just using a small handheld remote control for ease of testing. I wrote the code using each IR hex as if it was the vehicle, and turned them into a switch case. I have the segment displays operating and it recognizes the IR code I send it and will count up and reset as I want it to. Unfortunately the sensor bridge will pickup on several hits as it goes under it, and for the life of me I cannot seem to figure out how to write the code to ignore multiple reads of the same IR code. I basically need to get the IR sensor to read the first hit and forget the rest for a set amount of time or until the next time the truck goes through the sensor bridge....lets just say, read the first hit and ignore that same code for the next 10 seconds. Here is the code, any help would be great. Take it easy on me, I am very much a code beginner!!! I know I will have more questions along the way as I think this might be the most involved I have been in the code. This will eventually expand into up to 30 IR codes, and a multi-zoned IR sensor system.
#include "IRremote.h"
int receiver = 12; // Signal Pin of IR receiver to Arduino Digital Pin 11
int Blue = 11;
int Red = 7;
int lap_count1;
int lap_count2;
int latchPin = 4;
int clockPin = 5;
int dataPin = 3;
byte segdisp[10] = { B11111100,
B01100000,
B11011010,
B11110010,
B01100110,
B10110110,
B10111110,
B11100000,
B11111110,
B11100110,
};
/*-----( Declare objects )-----*/
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
void setup() /*----( SETUP: RUNS ONCE )----*/
{
Serial.begin(9600);
Serial.println("IR Receiver Button Decode");
irrecv.enableIRIn(); // Start the receiver
pinMode(Blue, OUTPUT);
pinMode(Red, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
digitalWrite(latchPin, LOW); // send to 7 segmetn displays
shiftOut(dataPin, clockPin, LSBFIRST, B11111100);
shiftOut(dataPin, clockPin, LSBFIRST, B11111100);
digitalWrite(latchPin, HIGH);
}/*--(end setup )---*/
/*-----( Function )-----*/
void translateIR() {// takes action based on IR code received
int a;
int b;
int c;
int d;
a = lap_count1%10;
b = lap_count1/10;
c = lap_count2%10;
d = lap_count2/10;
{
switch(results.value) // describe IR codes and what they will do
{
case 0xFF02F:
Serial.println("Driver 1"); // GREEN button on tape light remote
digitalWrite(Blue, HIGH);
lap_count1 ++;
Serial.println(lap_count1);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, segdisp[a]);
shiftOut(dataPin, clockPin, LSBFIRST, segdisp[b]);
digitalWrite(latchPin, HIGH);
digitalWrite(Blue, LOW);
break;
case 0xFF22D: Serial.println("Driver 2"); // RED button on tape light remote
digitalWrite(Blue, HIGH);
delay(50);
digitalWrite(Blue, LOW);
lap_count2 ++;
Serial.println(lap_count2);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, segdisp[c]);
shiftOut(dataPin, clockPin, LSBFIRST, segdisp[d]);
digitalWrite(latchPin, HIGH);
break;
case 0xFFA25: Serial.println("Reset"); // Play/Pause button on tape light remote
digitalWrite(Red, HIGH);
lap_count1 = 0;
lap_count2 = 0;
Serial.println(lap_count1, lap_count2);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, B11111100);
shiftOut(dataPin, clockPin, LSBFIRST, B11111100);
digitalWrite(latchPin, HIGH);
delay(1000);
digitalWrite(Red, LOW);
break;
default:
Serial.println(" other button ");
}// End Case
}
}
void loop() { /*----( LOOP: RUNS CONSTANTLY )----*/
if (irrecv.decode(&results)){ // have we received an IR signal?
{
translateIR();
irrecv.resume(); // receive the next value}
} } }
/* --(end main loop )-- */