Hello,
I am trying to get Arduino to read 3 characters input from the serial monitor. The goal is to have the user type in a 3 character message, such as ABC, and have Arduino read these characters from the buffer and save them to variables called byte1, byte2, and byte3. I then want to execute different code based on what the message is. However, if I type ABC in the serial monitor, Serial.available() does not return 3. I am fairly new to Arduino, and perhaps I am not understanding the various variable types.
Here is my code:
byte byte1;
byte byte2;
byte byte3;
void setup(){
//Initialize serial communication
Serial.begin(9600);
}
void loop() {
//Read Buffer
if (Serial.available()== 3) {
//Read buffer, store each byte to a variable
byte1 = Serial.read();
delay(100);
byte2 = Serial.read();
delay(100);
byte3 = Serial.read();
}
}
Any suggestions?
Thanks