i have these two sketches in my arduino. one is sketch is for reading serial numbers sent by an rfid reader and the other is turning an LED on by sending a letter in my serial monitor/PC application.
The RFID code came from Seedstudio
#include <SoftwareSerial.h>
String msg;
char inChar;
int x;
SoftwareSerial Rfid(2, 3); // RX as pin 2
void setup()
{
Serial.begin(9600);
Rfid.begin(9600);
}
void loop()
{
while (inChar = Rfid.read() != 2) // Wait for start byte from Rfid reader when tag is swiped
{
}
msg = "";
for (x = 0; x < 12; x++)
{
delay(10);
inChar = Rfid.read();
msg += inChar;
}
Serial.print(msg); // Sends the ID plus the checksum byte (12 bytes)
}
2nd sketch LED on:
int ledpin = 9;
byte byteread
void setup()
{
pinMode (9,OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
byteread = Serial.read();
if (byteRead == '1'){
digitalWrite(9,HIGH);
delay(3000);
digitalWrite(9,LOW);}
}
}
Problem: when i combine the two codes together, i only get the reading from the rfid reader, and when I send the number 1, it doesnt turn on the led,, Can anyone help me with these serial events?