I am using a Leonardo board and am testing the APIs in the Serial type. The board is talking to a screen using serial.
The pseudo code is as follows (I show code relevant to Serial):
void setup(void) {
Serial.begin(115200);
}
void loop(void) {
if(Serial.available())
{
if (Serial.find(0x30))
{
func1();
}
if (Serial.find(0x31))
{
func2();
}
}
}
void func1()
{
// Serial.print() used multiple times
asm volatile (" jmp 0");
}
void func2()
{
// Serial.print() used multiple times
asm volatile (" jmp 0");
}
I test using the Arduino IDE (1.8.0) and its Serial Monitor. When I send 0x30 over serial, the first if case gets triggered to invoke func1, but when I send 0x31, I cannot get the second if case (func2) to get triggered. This even happens when I test 0x31 first; the second if case never gets triggered. Can someone tell what I am doing wrong here and what is the right way to use serial ?
Edit For testing, one can use the pseudo code itself; I tested using different number of LED blinks in func1 & func2, and the problem still holds.
Edit 2 Based on Dave's answer, I tried a test with serial using sample code from
I did another test where I used the sample loop code for read (https://www.arduino.cc/en/Serial/Read) and tried typing 0 or 1 through serial monitor. I observed the following:
// Typed 0
I received: 48
I received: 13
I received: 10
// Typed 1
I received: 49
I received: 13
I received: 10