{
for (byte counter=seqLength; counter>=0; counter--) //--DAMMIT. if counter>=0, does not turn around at 0, wraps around to 255 and continues to decrement
//if counter>0, turns around but does not output 0: "4, 3, 2, 1, 1, 15..." (no delay after the second 1))
{
displayBinary(counter);
Serial.println(counter);
delay(seqSpeed);
}
}
seqLength and seqSpeed are variables; displayBinary is a routine to convert output to binary on 4 digital pins.
A byte is an unsigned type so it can't become negative. So 0 - 1 will roll around to the greatest value 255. A signed char can be negative but the greatest value is 127.
So instead for checking:
for(byte i = 10; i < 0; i--) //will never stop because i can not become negative
You can use the fact it will just roll around and check for
for(byte i = 10; i != 255; i--) //will happen because i will become 255 after subtracting 1 from 0
Ok, got it, any data type that handles negative values will work. Signed char was chosen in this case because the value "counter" is not exceeding 127. Or, use this: i != 255; with byte, so i will never be 255. Thank you very much for the explanation septillion. +1 karma