Run motor at <speed> for <time>
I'd like to do the following:
Button is pressed and held down
Motor starts at 50% for 5s, then jumps to 100%
Motor remains at 100% as long as button is held
Button is released, motor stops
Button is pressed again, motor starts again at 50% for 5s
I know I'll need a timer and probably a counter (or use maths?), but not sure how to tie them together.
Something like
if button = true then start timer
if timer <=5 then counter = 0, else counter = 1
if counter = 0 then output PWM = 50, else output PWM = 100
??
98 Views
My apologies, I got the PWM mapping wrong. I have verified that this works.