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.