Étape 5: Parallaxe lampe
1. fil SIN dans la broche numérique 3.
2. câbler SOUT à la broche numérique 2.
3. Télécharger la bibliothèque NewSoftSerial http://arduiniana.org/libraries/newsoftserial/
4. Transférez le code sur Arduino. Ce code lit les cartes RFID :
#include < NewSoftSerial.h > char tags_buffer [12] ; NewSoftSerial RFID = NewSoftSerial(rxPin,txPin) ; void setup() {} Serial.Begin(9600) ; void loop() {} void sendRead() {} void readTag() {} if(bytesRead == 12) {} pour (int i = 0; i < 3; i ++) {} {if(MSG==tags_buffer)} cas 1 : cas 2 :
#define rxPin 2
#define txPin 3
octet r = 0, g = 0, b = 0 ;
prog_char rouge [] PROGMEM = "2F00E69DFF" ;
prog_char vert [] PROGMEM = "2F00E68BC6" ;
prog_char bleu [] PROGMEM = "2F00E6C2D0" ;
Les const char PROGMEM * [] colorTags_table = {}
rouge, vert, bleu} ;
RFID.begin(9600); / / RFID reader SOUT broche reliée à la broche RX série à 9600bps
}
sendRead() ;
readTag() ;
}
RFID.flush() ;
RFID.print("!RW") ;
RFID.print (0x0F, BYTE) ;
}
byte-code [12] ;
bytesread int = 0 ;
String msg ;
while(bytesRead<12) {/ / lecture de 10 chiffres
cela bloque et devrait idéalement avoir un timeout
Si (RFID.available()) {}
Code [bytesread] = RFID.read() ;
bytesRead ++ ;
}
Si (code[0]==0x0A) {}
Serial.Print ("TAG code est:") ;
pour (int i = 1; i < 11; i ++) {}
MSG = msg + code [i] ;
}
strcpy_P (tags_buffer, (char *) pgm_read_word (&(colorTags_table[i])));
{Switch(i)}
case 0 :
Serial.println("Red") ;
r = 255 ;
rupture ;
g = 255 ;
Serial.println("Green") ;
rupture ;
b = 255 ;
Serial.println("Blue") ;
rupture ;
}
}
}
}
}
}
}