Filling out more functions and timers, untested

This commit is contained in:
dogma 2023-11-22 06:01:15 -06:00
parent f9e588e0cf
commit 36fab27821

56
main.py
View File

@ -18,6 +18,7 @@
Shaft diameter is 5mm with a 3mm inner key thing. Mounting holes are 35mm apart. """
import machine
from machine import Pin
from machine import Timer
import math
@ -77,6 +78,7 @@ def ypt(ts):
# 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)
def step_motor():
"""
This is the callback function that gets called when te timer
@ -86,27 +88,73 @@ def step_motor():
"""
pass
def do_step(current_step):
# 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():
pass
setup_gpio()
setup_timer()
buttonUp = Pin(MODE_PIN)
if not buttonUp:
print("Manual REWIND")
autostop = False
current_mode = REWINDING
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():
for i in NUM_PINS:
Pin(motorPins[i], Pin.OUT)
all_pins_off()
button = Pin(MODE_PIN, Pin.IN)
button.irq(trigger=Pin.IRQ_FALLING, handler=toggle_mode)
pass
def all_pins_off():
for i in NUM_PINS:
Pin(motorPins[i], Pin.low())
def toggle_mode():
# We have several modes that we can toggle between with a button,
# 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
def loop():
pass