[ SOLVED ] Toggle condition is not change


hi all,

need , advise in arduino toggle condition,

here part of code, it's led controller when input command using serial :




code: [select]
if(indata.substring(7,10)=="001"){
              pinf = pinf | 0b00000001; // toggle led1            
            }else if(indata.substring(7,10)=="002"){
              pinf = pinf | 0b00000010; // toggle led2              
            }else if(indata.substring(7,10)=="003"){
              pinf = pinf | 0b00000100; // toggle led3              
            }else if(indata.substring(7,10)=="004"){
              pinf = pinf | 0b00001000; // toggle led4
            }

 

test code result :
- when send "001" serial led1 on, , off when send "001" again ( result = ok ).
- when send "002" serial led1 on, , off when send "002" again ( result = not ok ).
- when send "003" serial led1 on, , off when send "003" again ( result = not ok ).
- when send "004" serial led1 on, , off when send "004" again ( result = not ok ).

the question why led1 respons command,
"002" should led2
"003" should led3
"004" should led4,

is there wrong or missing code ?

thanks

in code use inclusive or operator, in order toggle bits need use exclusive or operator, symbol ^


Arduino Forum > Using Arduino > Programming Questions > [ SOLVED ] Toggle condition is not change


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts