Perhaps not to you, but this one caught me underwears:
I failed to check the type of variable I had in front of me and thought that incrementing it would toggle the bottom bit. Sooner or later (OK, a lot later) I did check, it was boolean which is Ard-speak for bool (why?!). Changing it to unsigned char with which I am more familiar changed fixed it!
My friend google helped me out
"Incrementing an object with bool type results in its value been [sic] set to true."
but there's no replacing the hair I tore out.
This will happen to me again. May it never happen on you.
alto777:
it was boolean which is Ard-speak for bool (why?!)
The Arduino IDE is based on the Processing IDE. I think the original idea was to make something that would provide the same beginner-friendly experience programming microcontrollers as Processing does on computers. The two projects would be somewhat complementary. For this reason, you'll notice a lot of similarities between the Arduino standard API and the Processing language. Processing language is based on Java, which uses the boolean type (byte too). Years later, I think only a small percentage of Arduino users also use Processing so there is not such an advantage. In the case of boolean vs bool, I think the disadvantages of using a non-standard type alias far outweigh the minor benefits. For this reason, I undertook a project to encourage the use of bool instead of boolean.
In the case of byte vs unsigned char, I do think the advantages of a more beginner friendly type name outweigh the disadvantages. "unsigned char" just doesn't make intuitive sense like byte does.
A bool holds one of two values, true or false. (Each bool variable occupies one byte of memory.) (Arduino Reference)
So what happens in the following snippet ?
bool thebool=true;
while (thebool) {
thebool++;
Serial.print('.');
}
Serial.println('*');
Deva_Rishi: A bool holds one of two values, true or false. (Each bool variable occupies one byte of memory.) (Arduino Reference)
So what happens in the following snippet ?
bool thebool=true;
while (thebool) {
thebool++;
Serial.print('.');
}
Serial.println('*');
Just a long line of dots. It never wraps back to zero.