On 1/18/2017 10:07 AM, Evan Koblentz via vcf-midatlantic wrote:
We already tried using a variable. In that example, I built a Lego V-8 style motor. Pressing joystick button 0 one time starts it. I wanted the next button 0 press to stop it. As Dean said, it didn't work using the variable method because of (we think) timing issues. It works fine in walkie-talkie style mode (Dan that's just like the code you and I made ahead of Maker Faire) where "IF NOT BUTTON? 0 [TTO "(port number) OFF] and it also works fine if I have button 1 turn it off. But our attempts to have button 0 turn it on, change a variable to represent that, then check the variable again upon the next button press and turn it off it the variable = 1 just didn't work reliably. The motor stuttered and * sometimes * turned off. Sometimes it worked reliably for a few minutes and then wouldn't work at all.
Another place where I need to check motor status (port on/off status) is for the steering rack. As in a real car, the steering has a mechanical limit. Imagine if you had superhero strength: you could keep turning the steering wheel at its limit and you'd break some component. In the Lego model, if a kid holds the joystick to one side after that limit is reached, then either the Lego pieces start coming apart or the motor could burn out. So I put the optical sensor there. When the sensor is blocked, it turns off the steering rack port. Kind of ingenious right? :) But it doesn't work because the program does not know which master to obey -- the joystick telling it to spin the steering motor or the sensor telling it to stop! I tried some code saying if the sensor is true and the motor is true then turn off the port, but couldn't get that to work. There is chance it was my code at that point, not the logic.
All these problems could be avoided if I had a simple way to check a port status. "Hey I see a button was pressed? Is the port on? Okay, turn it off. Oh was it off? Okay, turn it on." Evan Koblentz, director Vintage Computer Federation A 501(c)3 educational non-profit http://www.vcfed.org
All these problems could be avoided if I had a simple way to check a port status. "Hey I see a button was pressed? Is the port on? >Okay, turn it off. Oh was it off? Okay, turn it on."
Maybe. Perhaps there is another explanation: Consider whether when you press button 0- does LOGO give you ONE indication or is it as LONG as you hold it it gives you continuous "button pressed" indications? This is a typical problem with button processing. IF LOGO gives you BUTTON PRESSED continuously (as I suspect) then what is happening is you are toggling your motor on and off continuously and when you release it you have a pretty much 50-50 chance of it being on or off. IF this is the case you have to put in specific logic to only process the first indication of the press and ignore the rest until you see a release of the button. Make sure this is not the case, because if is is, the port status in fact will not help at all. They very likely give continuous indication that a button is pressed because that has its purposes too and tends to be a norm in my experience... let the user catch the first one of that is what he(she) is interested in. As for the sensor:
But it doesn't work because the program does not know which master to obey -- the joystick telling it to spin the steering motor or >the sensor telling it to stop! I tried some code saying if the sensor is true and the motor is true then turn off the port
You were on the right track for that, the joystick cannot command the motor if the sensor has triggered. sensor routine shuts off the mother and sets an varaible. Joystick, on press, only starts the motor if the sensor for that direction has not hit. If that logic is not achievable in LOGO then it is a total failure, something must be fixable here. It is normally perfectly reasonable to represent the motor's status in a variable.