c++ - Arduino Project Needs Print Statements to Work -


I have this Arduino code which I'm going to get through some of the serials + this information is being written in connection , But I see some very weird behavior on the Arduino side.

If I do not put print statements (especially non-print RGB) in details, I do not see any output in the serial console as soon as I add them, they start to appear again. Are there. What is happening?

#define LED_PIN 13 #define R_PIN 3 #define G_PIN 5 #define B_PIN 6 # Define the frame ((four) 255) four colors [] = {0,0,0}; Zero setup () {serial.begin (9600); Pinomoda (LDIPN, output); Pinomoda (ripin, output); Pinomoda (gpin, output); Pinomoda (bpin, output); // Installation Company (); Serial.println ("blah"); } Zero loop () {if (serial.available ()> gt; 0) {char inByte = serial.read (); ToggleLED (); // got a new frame // serial.printLN ('s'); If (inByte == framebusiness) {//Serial.println('B '); // bass boolean allThree = true; {Char rgb = serial.read () for (Int i = 0; I

This is a bit strange, because time and conversion first: you read a byte Are inserted in "Inbit". We know serials Reid (-1) can not be returned because we are sure that at least one byte is very important: Note that in intersection of -1, byte (UIT 8_T) is secretly 255 (meaning your (255) -1, see why 2 are complementary)

Then you do some code really fast, but you can tease the serial. Print () The witch will slow it down.

Then you can read 3 bytes without taking 3 bytes; With serial.print () you added delay, easily, you read this byte, but the strange print () your code is so fast (9600 baud rate means 960byte / s !! is really slow) that any byte Has not arrived and you get 1 from alwayr serial. Reed (Witch means "nothing to read") and you can convert it to four (now -1), but then print it (uint8_t), and so it has been authorized and its value 255

Tested on my arduino uno, IDE 1.5.4


Comments