Quote (SIKKaudio @ Jan 10 2017 09:11am)
IDK what this is, but I'll look into it for future projects.
Don't worry about it, he was just trying to seem smart by suggesting something useless. A teensy is just a Uno but smaller form factor using a attiny microcontroller. Provides all the same functionality and more limited feature set.
Quote
We are using a BrightSign 1032 right now as a media player, but it's a bit pricey, I think we will be going the route of adding a raspi in-place of the brightsign player.
I still need to reverse the code a bit so instead of playing the video if you scan the tag, that it plays when you remove the tag.
This is what I have so far, and it works perfect except for the end where it needs to activate when I remove the tag not place the tag.
E/ could it be as simple as flipping the HIGH and LOW around?
E2/ switching HIGH and LOW around would work but I would need to replace the delay with something else, some sort of trigger mechanism instead of the timer
If you need to pull the pin high due to protocol then the only way to do it is to reverse the digitalWrite() calls.
I would refactor the code something like this:
Code
#define koffies 2
#define thees 2
String *koffie_rfid[] = { "46e6868d", "5aadebb"};
String *thee_rfid[] = { "46528b8d", "ea35fbb"};
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial ())
return;
for(int i = 0; i <= koffies; i++) {
if(koffie_rfid[i] == read_rfid) {
digitalWrite(koffiePin, HIGH);
} else {
digitalWrite(koffiePin, LOW);
}
}
for(int i = 0; i <= thees; i++) {
if(thee_rfid[i] == read_rfid) {
digitalWrite(theePin, HIGH);
} else {
digitalWrite(theePin, LOW);
}
}
}
What this should theoretically do is keep setting the pin high while the rfid tag is being read and it matches one of the two ids. Then when the rfid tag is removed it should set it low.
Although this may not work seeing how you return if you can not read the card or if the card is not present. Another possibility would be:
Code
#define koffies 2
#define thees 2
String *koffie_rfid[] = { "46e6868d", "5aadebb"};
String *thee_rfid[] = { "46528b8d", "ea35fbb"};
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
digitalWrite(koffiePin, LOW);
digitalWrite(theePin, LOW);
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial ()) {
digitalWrite(koffiePin, LOW);
digitalWrite(theePin, LOW);
return;
}
for(int i = 0; i <= koffies; i++) {
if(koffie_rfid[i] == read_rfid) {
digitalWrite(koffiePin, HIGH);
}
}
for(int i = 0; i <= thees; i++) {
if(thee_rfid[i] == read_rfid) {
digitalWrite(theePin, HIGH);
}
}
}
This will set the pin high, and then when the rfid card is removed and can not be read it will reset both pins to low.
There is more ways to refine this such as exporting the two mfrc522 calls to its own function to reset pins:
Code
#define koffies 2
#define thees 2
String *koffie_rfid[] = { "46e6868d", "5aadebb"};
String *thee_rfid[] = { "46528b8d", "ea35fbb"};
bool card_in_place() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
digitalWrite(koffiePin, LOW);
digitalWrite(theePin, LOW);
return false;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial ()) {
digitalWrite(koffiePin, LOW);
digitalWrite(theePin, LOW);
return false;
}
return true
}
void loop() {
if(!card_in_place)
return;
for(int i = 0; i <= koffies; i++) {
if(koffie_rfid[i] == read_rfid) {
digitalWrite(koffiePin, HIGH);
}
}
for(int i = 0; i <= thees; i++) {
if(thee_rfid[i] == read_rfid) {
digitalWrite(theePin, HIGH);
}
}
}
This segregates the logic a bit into something more manageable that makes some sense.
Hopefully this gives you some ideas. Basically how I would try to solve this is to either use the isnewcardpresent() and readcardserial() calls to reset the pins if they fail, or setup some kind of watch dog interrupt to catch when a card is removed. Using a interrupt would be the best if the library supports it. This way your code can be doing other stuff, and then when the cards are added or removed it will run a specific function you tell the interrupt to use as soon as they are added/removed, and then it will resume running the previous code. It makes life much easier in the long run since the interrupt functions can set the pins you need high/low only when they need to be rather than every iteration of the loop() function.
Edit:: I didnt add some code so I would compare examples and fix them. I think I missed the function that reads the ID from the reader somewhere.
This post was edited by AbDuCt on Jan 10 2017 08:16pm