Can anyone tell me what difference did it make when I made the following change? Initial Code [/b] ** **if(ch1==0 && PINB & 00000001) { ch1=1; time1=current_time; } if(ch1==1 && !(PINB & 00000001)) { ch1=0; rch1 = current_time - time1; }** ** Final code:[/b]
**__ <strong>** if(PINB & B00000001){ //Changed made conditoned seperated if(ch1==0) { ch1=1; time1=current_time; } } else if(ch1==1) { ch1=0; rch1 = current_time - time1; }**</strong> __** After I made the above change i got the desired output
One difference is that both are now using the same value of PINB. In the first example you read PINB twice and it is possible for the value of bit 0 to have changed between them.