void writereg() {
digitalWrite(latchPin, LOW);
for (int i = 7; i >= 0; i--) {
digitalWrite(clockPin, LOW);
Serial.print("wswitch&&&&&&");
Serial.print(i);
Serial.print("----------------------");
digitalWrite(dataPin, switches[i].stat);
Serial.println(switches[i].stat);
digitalWrite(clockPin, HIGH);
}
digitalWrite(latchPin, HIGH);
touched = false;
}
I don't understand what's wrong with what I'm doing here, but this for loop runs into an almost infinite loop and prints crazily. I'm a newbie to electronics and Arduino and I don't understand what's wrong here. Please help.
This is my switch class:
struct Swtch
{
int num;
bool stat;
bool touched;
};
Swtch switches[8] = {{1, 0, 0}, {2, 0, 0}, {3, 0, 0}, {4, 0, 0}, {5, 0, 0}, {6, 0, 0}, {7, 0, 0}, {8, 0, 0}};
i
is not anint
but abyte
(orunsigned char
oruint8_t
). In this case, what you observe is normal because anunsigned
is always positive, hence the loop never ends. Are you sure the output posted here matches the code in your question?switches
was declared (and details of the underlying type)?i
is anint
. Just in case, do you have special compilation options?