Let's Make Robots!

Help with Variables in Basic

This is a chunk of code I am using for my big tracks bot. I am using a irin command to accept inputs from a tv remote i.e. 2 is fwd, 4 is left, 6 is right etc. I am using #5 to goto my write command to enter the number of times I have hit each button onto my EEPROM chip. The Problem I am having is that the variable changes!! I have no idea why. Here is the code with some notes as to the problem. Any ideas?


let b8=0

low 1 : low 2
irin 0,b5
if b5 = 1 then fwd
if b5 = 4 then writeit
goto main

let b8=b8+1

debug 'if I debug here I get the correct count for how many button pushes I did
pause 50
goto main

debug 'if I debug here b8 has changed. HUH?
i2cslave %10100000, i2cslow, i2cbyte
writei2c 1,(b8)
goto main

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hey Chris, I found this out with my ir remote for my robot too.

When I read an acceptable code into the key code variable (i.e. your b5) the next time it comes through your main loop b5 is STILL 1 even if nothing is recieved, in which case it goes to fwd and increments by 1 until a different key code comes through.

Remember even if you dont push any buttons a 2nd time the variable b5 is the same as it was the last time.

After let b8=b8+1 try setting b5 back to 0 or -1 or something you know means invalid, so it wont continually loop the fwd block.


Hope this helps, although I know nothing about basic so take it with a giant pinch of salt :)

Ezekiel might be on to something. Could it be that your input is read more than once? I suppose your debug in fwd would show increasing numbers without giving more inputs. And that is not how you describe it.

Resetting b5 in fwd would not help, since main would read it in again. Resetting tha actual IR receiver would be a better way.

Didn't I see you succesfully demonstrating this? Does it mean your problems was solved? How?


Is there system in this error? Is it always too high / too low?

What if you debugged in main, just before calling writeit?


PS: Shouldn't that say

if b5 = 5 then writeit