On 1/18/2017 12:35 PM, David Gesswein via vcf-midatlantic wrote:
On Wed, Jan 18, 2017 at 10:07:31AM -0500, Evan Koblentz via vcf-midatlantic wrote:
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.

Insufficent information so this could all be known/offbase.

If it was coded as something like this

motor_on = false
loop till end of time
   if not motor_on and button pressed
      turn on motor
      motor_on = true
   else if motor_on and button pressed
      turn off motor
      motor_on = false
   end if
end loop

Then you would get behavior like you said. The stuttering would be
First loop
  Motor is off and button pressed so turn it on
Next loop
   Motor is on and button is still pressed so turn it off
Next loop
   Motor is off and button is still pressed so turn it on
...

If the loop is fast enough that you don't
hear the stuttering it would randomly be on or off when you let up
the button based on how many times it went through the loop while
the button was pressed.

The fix would be instead of button pressed check if button pressed
and was not pressed last time through the loop.

If the loop is fast enough you may then get another problem caused
by switch bounch. Switches don't cleanly transition from on to off
or the opposite. Instead they will generate a sequence of on's and
off's if you sample them fast enough. Random web page showed someone
measuring a switch bounce of 157 milliseconds. To cure this you need
to ignore additional transitions for some time after the first. Switch
bounce gets worse with age which is why you get extra characters on
old buttons. The put in debounce for the new switch bounce time
but it now bounces longer.

Ah the code! 
Yep.  Dave is on the same track as I was.
It could be switch bounce, or it could be LOGO reports "button pressed" as true as
long as the button is held down.  That logic will not insure that you only process the first
button press and ignore further "button pressed" until release of the button.
Dave may be right, it could be bounce.  They should have taken care of that in LOGO.
But the code you have assumes that you would only get ONE button pressed = true instead
of continuous button pressed = true as long as the system sees the button down.
If that assumption is incorrect, the fix is something like this:

Only process the FIRST button pressed = true, ignore the rest, using "got_first_down"
motor_on = false
first_one = true  // allow next one.
loop till end of time
   if first_one
      if button pressed
         first_one = false // lockout until released
         if not motor_on
            turn on motor
            motor_on = true
         else 
            turn off motor
            motor_on = false
         end if
      end if
   else
      if not button pressed
         first_one = true // released.
      endif
   end if
end loop