shaunmorgan
New member
So if I use this code and type in to the serial window 2 numbers or 4 numbers the code seems to work just fine. Once I enter an odd number of numbers, it will return a -1 for the number I did not enter. Now what happens is the device continues to print double negative 1's as if I had entered numbers in a loop. Even if I try enabling the serial.end(); The serial does not stop and it continues to print double -1's. Tested this on a teensy 2++ and it does not act like I entered these extra -1's.
Just tested this using char for the incoming values and I get
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
Any ideas?
code
int8_t led =13;
int8_t led1=23;
int8_t led2=22;
int8_t led3=21;
int8_t incomingByte;
int8_t incomingByte2;
void setup()
{
pinMode (13,OUTPUT);
pinMode (led1,OUTPUT);
pinMode (led2,OUTPUT);
pinMode (led3,OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 0 ) //then chars are in the serial buffer
{
incomingByte = Serial.read();
Serial.print("You entered: ");
Serial.println(incomingByte);
incomingByte2 = Serial.read();
Serial.print("You entered: ");
Serial.println(incomingByte2);
// Serial.end();
delay (2000);
}
}
Just tested this using char for the incoming values and I get
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
You entered: ÿ
Any ideas?
code
int8_t led =13;
int8_t led1=23;
int8_t led2=22;
int8_t led3=21;
int8_t incomingByte;
int8_t incomingByte2;
void setup()
{
pinMode (13,OUTPUT);
pinMode (led1,OUTPUT);
pinMode (led2,OUTPUT);
pinMode (led3,OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 0 ) //then chars are in the serial buffer
{
incomingByte = Serial.read();
Serial.print("You entered: ");
Serial.println(incomingByte);
incomingByte2 = Serial.read();
Serial.print("You entered: ");
Serial.println(incomingByte2);
// Serial.end();
delay (2000);
}
}
Last edited: