Hi all. It has been a while since I have been able to experiment with Arduino. My last project was accomplished by the help from everyone on this forum. Life got in the way since my last project but am trying to get back into it.
Last time you all helped me with building an IR lap timer to communicate with Zround lap timing software. That has been great and have been using it for years now. I think I have hit the limit to what IR can do for me. I just purchased the new Sparkfun Simultaneous RFID reader and some tags. I am hoping to adapt the code/sketch to make this work with little changes. I have played with the reader a bit to get an idea on how things work, but I am now back in over my head with trying to rewrite the code (I am great with hardware, crap with code). Here is the original IR lap timer code, written by someone on Github and adapted for 4 IR zones by myself and another member.
#include <IRremote.h>
int m, s, mu=0, md=0, su=0, sd=0, l=0, lu=0, ld=0, lc=0, redLed=5, gate=6, reset=7, greenLed=4, zround=0, tx=0, timer=0, connect=1, led_status = 1;
const int RECV_PIN = 9;
const int RECV_PIN2 = 10;
const int RECV_PIN3 = 11;
const int RECV_PIN4 = 12;
long int time, timeStart;
IRrecv irrecv(RECV_PIN);
IRrecv irrecv2(RECV_PIN2);
IRrecv irrecv3(RECV_PIN3);
IRrecv irrecv4(RECV_PIN4);
decode_results results;
decode_results results2;
decode_results results3;
decode_results results4;
char message[3];
// **********************************************************************************
void setup() {
Serial.begin(19200);
pinMode(redLed,OUTPUT);
pinMode(greenLed,OUTPUT);
pinMode(gate, OUTPUT);
pinMode(reset, OUTPUT);
irrecv.enableIRIn();
irrecv2.enableIRIn();
irrecv3.enableIRIn();
irrecv4.enableIRIn();
connect_Zround();
}
void loop() {
}
// **********************************************************************************
void connect_Zround() {
int flash = 0;
while (connect == 1) {
led_indicators();
// Read Message from Serial Port
while (Serial.available() > 0) {
for (int i = 0; i < 3; i++) {
message[i] = Serial.read();
delay(50);
}
}
// Message: Connection from Zround "%C&"
if (message[0] == '%') {
if (message[1] == 'C') {
if (message[2] == '&') {
int count = 0;
while (count <= 20) {
// Message: Confirmation "%A&"
Serial.write("%A&");
delay(100);
count++;
}
led_status = 2;
message[0] = ('0');
}
}
}
// Start Practice or Race
if (message[0] == '%') {
if (message[1] == 'I') {
if (message[2] == '&') {
timeStart = millis();
connect = 0;
timer = 1;
zround = 1;
initiate_timer();
}
}
}
delay(50);
}
}
// **********************************************************************************
void initiate_timer() {
while (zround == 1) {
while (Serial.available() > 0) {
for (int i = 0; i < 3; i++) {
message[i] = Serial.read();
delay(50);
}
}
led_status = 4;
led_indicators();
timeStart = millis();
timer = 1;
while (timer == 1) {
time = millis() - timeStart;
m = time / 60000;
mu = m % 10;
md = (m-mu) / 10;
s = (time/1000) - (m*60);
su = s % 10;
sd = (s-su) / 10;
l = time - (s*1000) - (m*60000);
lu = l % 10;
ld = ((l-lu) / 10) % 10;
lc = (l - (ld*10) - lu) / 100;
if ( su == 0) {
if (lu == 0 && ld == 0 && lc == 0) {
Serial.print("%T");
Serial.print(time,HEX);
Serial.println("&");
}
}
if (su == 5) {
if (lu == 0 && ld == 0 && lc == 0) {
Serial.print("%T");
Serial.print(time,HEX);
Serial.println("&");
}
}
if (irrecv.decode(&results)) {
tx = results.value;
lap_counter();
irrecv.resume();
}
if (irrecv2.decode(&results2)) {
tx = results2.value;
lap_counter();
irrecv2.resume();
}
if (irrecv3.decode(&results3)) {
tx = results3.value;
lap_counter();
irrecv3.resume();
}
if (irrecv4.decode(&results4)) {
tx = results4.value;
lap_counter();
irrecv4.resume();
}
while (Serial.available() > 0) {
for (int i = 0; i < 3; i++) {
message[i] = Serial.read();
delay(50);
}
}
// Check if Practice or Race has Ended
if (message[0] == '%') {
if (message[1] == 'F') {
if (message[2] == '&') {
timer = 0;
digitalWrite(redLed,LOW);
digitalWrite(greenLed,LOW);
connect = 1;
zround = 0;
led_status = 3;
connect_Zround();
}
}
}
}
delay(10);
}
}
// **********************************************************************************
void lap_counter() {
check_transponder();
if (tx!=0) {
digitalWrite(redLed, HIGH);
Serial.print("%L");
Serial.print(tx, HEX);
Serial.print(",");
Serial.print(time, HEX);
Serial.print("&");
Serial.println();
digitalWrite(redLed, LOW);
tx=0;
}
}
// **********************************************************************************
void led_indicators() {
switch (led_status) {
case 1: // Standby
digitalWrite(redLed,HIGH);
digitalWrite(reset,HIGH);
digitalWrite(gate,LOW);
digitalWrite(greenLed,LOW);
delay(200);
digitalWrite(redLed,LOW);
digitalWrite(greenLed,LOW);
delay(700);
break;
case 2: { // Connecting
int blink = 0;
while (blink <= 5) {
digitalWrite(redLed,HIGH);
delay(200);
digitalWrite(redLed,LOW);
delay(200);
blink++;
}
digitalWrite(redLed,HIGH);
digitalWrite(greenLed,LOW);
led_status = 3;
break;
}
case 3: // Connected
digitalWrite(redLed,HIGH);
digitalWrite(greenLed,LOW);
break;
case 4: // Race
digitalWrite(redLed,LOW);
digitalWrite(greenLed,HIGH);
digitalWrite(gate,HIGH);
delay(2000);
digitalWrite(gate,LOW);
break;
}
}
// **********************************************************************************
void check_transponder() {
// Backward compatibility
// Keeping this here in case you don't want to re flash your existing transponder.
//if (results.value >= 0xFFFF01 && results.value <= 0xFFFF12) {
if (tx >= 0x0 && tx <= 0xFF) {
}
else {
tx = 0;
}
}
I guess for starters I am asking if this can easily be done with just a few tweaks? I can write the same HEX code the IR transponders use to the RFID tags, so I assumed if I can get the code to interpret the RFID tag and make it think it is the same transponder(HEX) number than it should work the same way, correct? Or am I going about this all wrong and should start over? Since the simultaneous reader is fairly new there is not a whole lot out there as far as references to use on it. I have searched this and several other forums with no luck, yet I don't really know where to begin, so there could be a lot of info and I just don't know it. The hardware is working fine, so no problems there, this is all about code. The RFID reader is great and can't wait to get it fully functional for real world testing. Any help would be great guys, again, I am as close to a beginner in code as it gets. I learned a lot on my last project, but the last 2 years of my life has set me waaaay back in skills and I am basically starting over. Thanks all.