one part of code is working while the equivalent is not (BUTTON / IF...THEN)
Sebastien
Posts: 7
A very strange problem that I have. I don't understand anything.
I have a moving object that can be detected (and thus stopped ) by a reflective sensor (I exposed my machine in a recent thread (http://forums.parallax.com/showthread.php?p=547608).
When I use a BUTTON function to detect the changing of state of my sensor I encounter no problem, but when I use IF...THEN or DO...WHILE/UNTIL...LOOP functions there's a problem.
common code part :
that part works fine :
but that one is NOT working, whereas it is an equivalent coding (well, I think it is). Even when my object is static in front of my sensor (I know my sensor is working fine btw) and when "program" is supposed to be executed I'm falling into the "[noparse][[/noparse]...]" code part.
Even this is not working, I'm entering in an infinite loop.
I have conducted many different tests so as to understand what is the matter. In the end, I only come with these code lines. On one hand it's OK, on the other hand it's NOK.
Anybody got an idea ?
I have a moving object that can be detected (and thus stopped ) by a reflective sensor (I exposed my machine in a recent thread (http://forums.parallax.com/showthread.php?p=547608).
When I use a BUTTON function to detect the changing of state of my sensor I encounter no problem, but when I use IF...THEN or DO...WHILE/UNTIL...LOOP functions there's a problem.
common code part :
'main pins main_ENG_CLK PIN 4 'Clock engine main_ENG_ENA PIN 5 'Enable engine main_ENG_ROT PIN 6 'way of rotation '+ other pins declared 'aux pins aux_sensor PIN 4 'reflective sensor '+other pins declared
that part works fine :
main: BUTTON aux_sensor,1,0,0,workspace,1,program 'if sensor = 1 goto "program" [noparse][[/noparse]...] program: 'bla bla bla, the code stops the engine...
but that one is NOT working, whereas it is an equivalent coding (well, I think it is). Even when my object is static in front of my sensor (I know my sensor is working fine btw) and when "program" is supposed to be executed I'm falling into the "[noparse][[/noparse]...]" code part.
main: IF (aux_sensor = 1) THEN program [noparse][[/noparse]...] program: 'bla bla bla
Even this is not working, I'm entering in an infinite loop.
main: DO [noparse][[/noparse]...] UNTIL aux_sensor 'until = 1 program: [noparse][[/noparse]...]
I have conducted many different tests so as to understand what is the matter. In the end, I only come with these code lines. On one hand it's OK, on the other hand it's NOK.
Anybody got an idea ?
Comments
You should be able to detect the pin status and see it change with this:
Test:
· AUXIO
· DO
··· DEBUG HOME, BIN1 Aux_Sensor
· LOOP
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
When doing my 2 tests I'm strictly in the same conditions, nothing else is modified.
first test :
=> OK
second test :
=> NOK
Sadly, I'm not able to use the debug mode for the moment. My PC and my machine are not next to each other.
Just a thought: how long is that input low? BUTTON is sitting there waiting while the code in a loop is loading and reloading instructions -- a very quick low input could be missed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Best Regards
Manuel C. Reinhard
I am now able to use the DEBUG function with my PC. Thus, I verified the states of my sensor, depending on the position of my object.
If I use the debug loop you gave me Jon, the state of my sensor is never changing, but still the BUTTON function works whereas the IF...THEN doesn't.
Now, here comes the strange part :
If I write a BUTTON command line before (just before or at the very first beginning of my program, just after declarations) the debug test function, then the sensor behave the right way : 0 by default, 1 when the object is present. That means also that the IF...THEN function is now functionnal. I don't know if I'm clear so :
=> NOK
=> OK !! Here the IF...THEN function works ! Very weird.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax