Go Down

Topic: 'if' equation always firing... (Read 490 times) previous topic - next topic

frollard

I have a piece of code...

Code: [Select]
for (int i = 0; i < 8; i++) {
    temp = (j * 8) + i;
    temp3 = ledArray[temp];
    if (temp3 >= x ); {
    Serial.print(temp3, DEC);
    Serial.println(x, DEC);
    ledOut |= bit(i);
  }   //end if
   }  //next i

I had all the functions of temp3 = blabla embedded in the if statement, and took them out just to make sure.

Now...the way it works is I'm breaking an array of 24 into chunks of 8 for evaluation then shifting out to a shift register.
It used to work with just one shift register, but as soon as I made the array bigger it no longer works:
Serial Display:
Code: [Select]

01
01
01
01
01
01
01
01
After i, before shiftout
255

Zero is not greater than or equal to one, so it should not fire the if, but it does...8 times in a row.  No matter what data gets passed to this statement it doesnt seem to work.
255 is the decimal format of the bitwise setting of all 8 bits in the byte ledArray.

**back story, the whole point of this is I'm doing 3 bit (8 step) pwm control of an array of leds through shift registers by shifting at maximum speed.  I'm THIS close to giving up on the pwm concept - once the array gets as big as I hope (hundreds of leds) pwm will be unfeasable - but at this small prototyping stage I have some cool animations for an 8 led system...blargh.

Thanks in advance!  Please tell me I'm missing something stupid.

Mitch_CA

Looky here...
Code: [Select]
if (temp3 >= x ); {

You have a rogue ";"

Go Up