Filling out more functions and timers, untested
This commit is contained in:
parent
f9e588e0cf
commit
36fab27821
56
main.py
56
main.py
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
Shaft diameter is 5mm with a 3mm inner key thing. Mounting holes are 35mm apart. """
|
Shaft diameter is 5mm with a 3mm inner key thing. Mounting holes are 35mm apart. """
|
||||||
|
|
||||||
|
import machine
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
from machine import Timer
|
from machine import Timer
|
||||||
import math
|
import math
|
||||||
@ -77,6 +78,7 @@ def ypt(ts):
|
|||||||
# Note, if you run this for ~359 minutes, it goes to infinity!!
|
# Note, if you run this for ~359 minutes, it goes to infinity!!
|
||||||
return LENGTH_CM * RADS_PER_SEC/math.pow(math.cos(THETAO + RADS_PER_SEC * ts), 2)
|
return LENGTH_CM * RADS_PER_SEC/math.pow(math.cos(THETAO + RADS_PER_SEC * ts), 2)
|
||||||
|
|
||||||
|
|
||||||
def step_motor():
|
def step_motor():
|
||||||
"""
|
"""
|
||||||
This is the callback function that gets called when te timer
|
This is the callback function that gets called when te timer
|
||||||
@ -86,27 +88,73 @@ def step_motor():
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def do_step(current_step):
|
def do_step(current_step):
|
||||||
# apply a single step of the stepper motor on its pins.
|
# apply a single step of the stepper motor on its pins.
|
||||||
pass
|
for i in NUM_PINS:
|
||||||
|
if current_step[i] is 1:
|
||||||
|
Pin(motorPins[i], Pin.HIGH)
|
||||||
|
else
|
||||||
|
Pin(motorPins[i], Pin.LOW )
|
||||||
|
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
pass
|
setup_gpio()
|
||||||
|
setup_timer()
|
||||||
|
|
||||||
|
buttonUp = Pin(MODE_PIN)
|
||||||
|
if not buttonUp:
|
||||||
|
print("Manual REWIND")
|
||||||
|
autostop = False
|
||||||
|
current_mode = REWINDING
|
||||||
|
|
||||||
|
|
||||||
def setup_timer():
|
def setup_timer():
|
||||||
pass
|
machine.disable_irq()
|
||||||
|
timer = Timer(2)
|
||||||
|
timer.init(freq=1000)
|
||||||
|
timer.callback(lambda t:step_motor())
|
||||||
|
machine.enable_irq()
|
||||||
|
|
||||||
|
|
||||||
def setup_gpio():
|
def setup_gpio():
|
||||||
for i in NUM_PINS:
|
for i in NUM_PINS:
|
||||||
Pin(motorPins[i], Pin.OUT)
|
Pin(motorPins[i], Pin.OUT)
|
||||||
all_pins_off()
|
all_pins_off()
|
||||||
button = Pin(MODE_PIN, Pin.IN)
|
button = Pin(MODE_PIN, Pin.IN)
|
||||||
button.irq(trigger=Pin.IRQ_FALLING, handler=toggle_mode)
|
button.irq(trigger=Pin.IRQ_FALLING, handler=toggle_mode)
|
||||||
pass
|
|
||||||
|
|
||||||
def all_pins_off():
|
def all_pins_off():
|
||||||
for i in NUM_PINS:
|
for i in NUM_PINS:
|
||||||
Pin(motorPins[i], Pin.low())
|
Pin(motorPins[i], Pin.low())
|
||||||
|
|
||||||
|
|
||||||
def toggle_mode():
|
def toggle_mode():
|
||||||
# We have several modes that we can toggle between with a button,
|
# We have several modes that we can toggle between with a button,
|
||||||
# NORMAL, REWIND, and STOPPED.
|
# NORMAL, REWIND, and STOPPED.
|
||||||
|
# Need to find replacement for ESP.getCycleCount();
|
||||||
|
#if ESP.getCycleCount() - last_toggle < 0.2*CYCLES_PER_SECOND:
|
||||||
|
# return
|
||||||
|
if current_mode is REWINDING:
|
||||||
|
print("STOPPING")
|
||||||
|
current_mode = STOPPED
|
||||||
|
all_pins_off()
|
||||||
|
if not autostop:
|
||||||
|
step_num = 0
|
||||||
|
total_seconds = 0
|
||||||
|
totalsteps = 0
|
||||||
|
autostop = True
|
||||||
|
elif current_mode is NORMAL:
|
||||||
|
print("REWINDING")
|
||||||
|
current_mode = REWINDING
|
||||||
|
else:
|
||||||
|
print("RESTARTING")
|
||||||
|
current_mode = NORMAL
|
||||||
|
last_toggle = 0# FIND REPLACEMENT FOR ESP.getCycleCount();
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def loop():
|
def loop():
|
||||||
pass
|
pass
|
Loading…
Reference in New Issue
Block a user