I've been trying to get a for loop to run 9 times using the below code but can't get the loop to run.
void output() {
int r;
r = 1;
Serial.println("Output");
digitalWrite(Latch, LOW);
for (int r=1; r >= 9; r = r + 1) {
Serial.println("Test");
digitalWrite(DataOutput, Q[r]);
digitalWrite(ClockPin, HIGH);
digitalWrite(ClockPin, LOW);
}
Serial.println("Done For");
digitalWrite(Latch, HIGH);
digitalWrite(Latch, LOW);
}
asked Dec 17, 2017 at 18:51
2 Answers 2
Change
for (int r=1; r >= 9; r = r + 1) {
to
for (int r=1; r <= 9; r = r + 1) {
The for loop will only run while the second part is true.
answered Dec 17, 2017 at 18:57
The middle expression r => 9 in the for loop is wrong. This will only loop whilst r is greater than 9 and you are starting from r = 1. Change it to r <= 9.
answered Dec 17, 2017 at 19:00
lang-cpp