Programming Question

JSDL

Senior Member
Hi all, I have created a simple program in Blockly to read from an IR sensor. I have attached a screenshot from Blockly, as well as the Picaxe Basic code generated. My question is why is line 6 added to the code (the logical AND with IRCommand)? What purpose does this serve other than masking out the MSB which, from my understanding, would always be a 0 using the irin command (0-127). Please correct me if I am wrong. Thanks for the help.

blockly.jpg
code.jpg
 

Dartmoor

Member
I think it is because you have ticked the box for "TV remote (+1)"?
The purpose is intended to make the value the same as the number on the button pressed?
Eg button 1 gives a value of 0 and button 2 gives a value of 1 etc.
Therefore adding "+1" makes: button 1 gives a value of 1 and button 2 gives a value of 2 etc.

My advice is not to use it (just accept & use the value that is sent). I tried this on my first attempt with the tv remote in logicator (flowchart) and found that it incremented the variable each time round the loop!
 

Technical

Technical Support
Staff member
It is theoretically possible to send corrupt signals (e.g. using irout from another PICAXE) so the AND is there to ensure the irin signal is always valid.
The +1 is added if the 'tv remote' checkbox is ticked as explained by dartmoor above.
 
Top