Hi guys,
I'm new to both Arduino and coding, and electronics so floundering a bit here and hopefully looking for a little input from more experienced guys.
I have successfully created an Arduino based bomb prop for my airsoft site, but I was looking to make alterations and additional game modes, and have hit a brick wall.
to make thingw easier for myself I have tried to just create the new code as stand alone, and will encorporate it into the rest of the bomb code later.
The issue is this :-
I want to be able to read RFID tags and to time the amount of time each is in front of the reader - for a time domination game.
I have successfully been able to write a working code to differentiate between tags, and time them. However when trying to output the times to separate LED displays the system hangs?
I have also adapted a piece of code to display the same count down / up on the two LED displays so I know that both work and will display the time.
I am sure it is something either silly, stupid and right in my face but I cant get over it.
the code is below.
if I comment out the display lines the code works and will print to the serial display the times, but once the lines for the display are there the damned thing just hangs
Any clues, comments or suggestions are welcome.
and please go easy I have about 2 weeks of coding and 0 hours of electronics experience
Thanks
/*
* MFRC522 - Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH TAGS SPI W AND R BY COOQROBOT.
* The library file MFRC522.h has a wealth of useful info. Please read it.
* The functions are documented in MFRC522.cpp.
*
* Based on code Dr.Leong ( WWW.B2CQSHOP.COM )
* Created by Miguel Balboa (circuitito.com), Jan, 2012.
* Rewritten by Søren Thing Andersen (access.thing.dk), fall of 2013 (Translation to English, refactored, comments, anti collision, cascade levels.)
* Released into the public domain.
*
* Sample program showing how to read data from a PICC using a MFRC522 reader on the Arduino SPI interface.
*----------------------------------------------------------------------------- empty_skull
* Aggiunti pin per arduino Mega
* add pin configuration for arduino mega
* http://mac86project.altervista.org/
----------------------------------------------------------------------------- Nicola Coppola
* Pin layout should be as follows:
* Signal Pin Pin Pin
* Arduino Uno Arduino Mega MFRC522 board
* ------------------------------------------------------------
* Reset 9 9 RST
* SPI SS 10 53 SDA
* SPI MOSI 11 51 MOSI
* SPI MISO 12 50 MISO
* SPI SCK 13 52 SCK
*
* The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com.
*/
#include <TM1637Display.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 53
#define RST_PIN 9
unsigned long aTime;
unsigned long iTime;
unsigned long timeCalcVar;
unsigned long redTime = 0;
unsigned long yellowTime = 0;
unsigned long iZoneTime;//initial time for zone
byte team=0; // 0 = neutral, 1 = yellow team, 2 = red team
//boolean match = false; // initialize card match to false
//boolean access = false;
//LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
// set up LED clock display
#define CLK 2
#define DIO 3
TM1637Display display1(CLK, DIO);
// set up LED clock 2
#define CLK2 46
#define DIO2 44
TM1637Display display2(CLK2, DIO2);
// card colours initialise with no colour
int RED = 0;
int YELLOW = 0;
//byte Card0 [4]={230, 82, 70, 53};
byte storedCard[4];
//byte cards[3][4] = {
// {230, 82, 70, 53},
// {117, 74, 241, 13},
// {37, 18, 250, 13},
// {21, 17, 251, 13},
// {193, 227, 252, 82},
// {212, 243, 127, 46},
// {52, 144, 75, 46}
//};
void setup() {
// lcd.begin(16, 2);
display1.setBrightness(0x0f);
display2.setBrightness(0x0f);
Serial.begin(9600); // Initialize serial communications with the PC
Serial.print ("Ready");
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
}
void loop() {
// unsigned long secs = millis()/1000;
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent() ) {
return;
}
//lcd.clear();
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
Serial.println("");
for (int i = 0; i < 4; i++) { //
(storedCard[i] = mfrc522.uid.uidByte[i]);
// Serial.print (storedCard[i]);
// Serial.print (" ");
}
{
byte readCard[4] ; // This is our byte array to store UID mind that there are 4 and 7 bytes long UID
/*
for (int i=0; i < 4; i++){
isMaster(storedCard);
}
if (match) Serial.print ("Master Card");
else */
{
if (mfrc522.uid.uidByte[0] == 117 && mfrc522.uid.uidByte[1] == 74 && mfrc522.uid.uidByte[2] == 241 && mfrc522.uid.uidByte[3] == 13) {
// Serial.print ("RED");
RED = 1;
}
else if (mfrc522.uid.uidByte[0] == 37 && mfrc522.uid.uidByte[1] == 18 && mfrc522.uid.uidByte[2] == 250 && mfrc522.uid.uidByte[3] == 13) {
// Serial.print ("RED");
RED = 1;
}
else if (mfrc522.uid.uidByte[0] == 21 && mfrc522.uid.uidByte[1] == 17 && mfrc522.uid.uidByte[2] == 251 && mfrc522.uid.uidByte[3] == 13) {
// Serial.print ("RED");
RED = 1;
}
else if (mfrc522.uid.uidByte[0] == 193 && mfrc522.uid.uidByte[1] == 227 && mfrc522.uid.uidByte[2] == 252 && mfrc522.uid.uidByte[3] == 82) {
// Serial.print ("YELLOW");
YELLOW = 1;
}
else if (mfrc522.uid.uidByte[0] == 212 && mfrc522.uid.uidByte[1] == 243 && mfrc522.uid.uidByte[2] == 127 && mfrc522.uid.uidByte[3] == 46) {
// Serial.print ("YELLOW");
YELLOW = 1;
}
else if (mfrc522.uid.uidByte[0] == 52 && mfrc522.uid.uidByte[1] == 144 && mfrc522.uid.uidByte[2] == 75 && mfrc522.uid.uidByte[3] == 46) {
// Serial.print ("YELLOW");
YELLOW = 1;
}
// else;
Serial.println("");
Serial.println("yellowTime");
Serial.println(yellowTime);
Serial.println("redTime");
Serial.println(redTime);
Serial.println("");
display1.showNumberDec(yellowTime,true,4,0);
display2.showNumberDec(redTime,true,4,0);
if(RED == 1)
{
// team = 2;
iZoneTime=millis();
// digitalWrite(REDLED, HIGH);
redTime+=millis()/iZoneTime;
// Serial.println("");
// Serial.print ( "Red = ");
// Serial.print (RED);
delay(1000);
team=0;
iZoneTime=0;
// break;
}
// digitalWrite(REDLED, LOW);
else if (YELLOW == 1)
{
team = 1;
iZoneTime=millis();
// digitalWrite(YELLOWLED, HIGH);
yellowTime+=millis()/iZoneTime;
// Serial.println("");
// Serial.print( "Yellow = ");
// Serial.print (YELLOW);
delay(1000);
team=0;
iZoneTime=0;
// break;
}
RED = 0;
YELLOW = 0;
}
}
// mfrc522.PICC_HaltA();
}
/*
///////////////////////////////////////// Check Bytes ///////////////////////////////////
boolean checkTwo ( byte storedCard[], byte Card0[] ){
if ( storedCard[0] != NULL ) // Make sure there is something in the array first
match = true; // Assume they match at first
for ( int k = 0; k < 4; k++ ) { // Loop 4 times
if ( storedCard[k] != Card0[k] ) // IF a != b then set match = false, one fails, all fail
match = false;
}
if ( match ) { // Check to see if if match is still true
return true; // Return true
}
else {
return false; // Return false
}
}
////////////////////// Check readCard IF is masterCard ///////////////////////////////////
// Check to see if the ID passed is the master programing card
boolean isMaster( byte test[] ){
for (int i = 0; i < 4; i++) {
if ( checkTwo( test, Card0 ))
return true;
else
return false;
}
}
*/
moderator: added code tags -