unexpected bool behaviour


hi all,

i'm getting strange result when trying detect state change.

this running on teensy 3.6 fyi

the suspect is:
code: [select]
void blockchange()
{
//find out if block has changed
  for (int i=0;i<numsensors;i++) {
    if (ledstate[i] =! previousblockarray[i]) {
      haschanged[i] = true;
    }
    previousblockarray[i] = ledstate[i];
  
    //end loop

    if (mode == 'c' && !haschanged[i] && timer > timeout)  {
      mode = 'a';
    }
    else if (mode == 'c' && haschanged[i]){
  //a block has been moved, reset timer
      timer = 0;
    }
    else if (mode == 'a' && haschanged[i]){
      mode = 'b';
      timer = 0;
    }
  }
  
  timer++; // timer increment 1 every time main loop, calls blockchange.
  serial.print("timer= ");
  serial.println(timer, dec);
  serial.print("block1= ");
  serial.println(ledstate[0]);
}

 

ledstate goes between 1 , 0 every loop, , cannot life of me work out why.

this i'm getting @ console (note: there no pulldown on sensor 1, should have no impact on weirdness i'm seeing) :

code: [select]
mode = c
sensor 0 value = 0
sensor 1 value = 301
color not detectable
color not detectable
timer= 1
block1= 0
mode = c
sensor 0 value = 0
sensor 1 value = 269
color not detectable
color not detectable
timer= 1
block1= 1
mode = c
sensor 0 value = 0
sensor 1 value = 246
color not detectable
color not detectable
timer= 1
block1= 0


and full code context.
code @ github

any advice can give me appreciated. thanks

quick glance

code: [select]

    previousblockarray[i] = ledstate[i];
 
    //end loop

    if (mode == 'c' && !haschanged[i] && timer > timeout)  {


rings alarmbell in head - because have comment says that's end of loop, yet loop doesn't end 13 lines....


Arduino Forum > Using Arduino > Programming Questions > unexpected bool behaviour


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???