Compare commits

...

3 Commits

Author SHA1 Message Date
Peter L 761e0f6c8d remote debugging changes 2021-11-10 13:15:26 +01:00
Peter Lorenz d9c9d673fc Merge branch 'master' of https://git.theater.digital/johannes.payr/pizzabox-ctrl 2021-11-04 14:49:14 +02:00
Peter Lorenz 3002c7f2c2 added pin numbers 2021-11-04 14:44:19 +02:00
2 changed files with 62 additions and 31 deletions

View File

@ -5,27 +5,31 @@ import time
_PWM_MAX = const(65535)
_PWM_FREQ = const(2000)
_PIN_EN_MOTOR_VERT = const(0)
_PIN_A_MOTOR_VERT = const(0)
_PIN_B_MOTOR_VERT = const(0)
_PIN_EN_MOTOR_VERT = const(14)
_PIN_A_MOTOR_VERT = const(12)
_PIN_B_MOTOR_VERT = const(13)
_PIN_EN_MOTOR_HOR = const(0)
_PIN_A_MOTOR_HOR = const(0)
_PIN_B_MOTOR_HOR = const(0)
_PIN_EN_MOTOR_HOR = const(15)
_PIN_A_MOTOR_HOR = const(10)
_PIN_B_MOTOR_HOR = const(11)
_PIN_EN_BACKLIGHT = const(0)
_PIN_EN_FRONTLIGHT = const(0)
_PIN_EN_BACKLIGHT = const(17)
_PIN_A_BACKLIGHT = const(18)
_PIN_B_BACKLIGHT = const(19)
_PIN_EN_FRONTLIGHT = const(16)
_PIN_A_FRONTLIGHT = const(20)
_PIN_B_FRONTLIGHT = const(21)
_PIN_LED_RED_BTN = const(0)
_PIN_LED_BLU_BTN = const(0)
_PIN_LED_RED_BTN = const(2)
_PIN_LED_BLU_BTN = const(4)
_PIN_RED_BTN = const(0)
_PIN_BLU_BTN = const(0)
_PIN_RED_BTN = const(3)
_PIN_BLU_BTN = const(5)
_PIN_SENS_END_VERT = const(0)
_PIN_SENS_CNT_VERT = const(0)
_PIN_SENS_END_HOR = const(0)
_PIN_SENS_CNT_HOR = const(0)
_PIN_SENS_END_VERT = const(9)
_PIN_SENS_CNT_VERT = const(7)
_PIN_SENS_END_HOR = const(6)
_PIN_SENS_CNT_HOR = const(8)
CMD_MOT_V = 'V' # run vertical motor
CMD_MOT_H = 'H' # run horizontal motor
@ -90,7 +94,12 @@ pwm_mh.freq(_PWM_FREQ)
pin_mv_a = Pin(_PIN_A_MOTOR_VERT, Pin.OUT)
pin_mv_b = Pin(_PIN_B_MOTOR_VERT, Pin.OUT)
pin_mh_a = Pin(_PIN_A_MOTOR_HOR, Pin.OUT)
pin_mh_b = Pin(_PIN_B_MOTOR_HOR)
pin_mh_b = Pin(_PIN_B_MOTOR_HOR, Pin.OUT)
pin_bl_a = Pin(_PIN_A_BACKLIGHT, Pin.OUT)
pin_bl_b = Pin(_PIN_B_BACKLIGHT, Pin.OUT)
pin_fl_a = Pin(_PIN_A_FRONTLIGHT, Pin.OUT)
pin_fl_b = Pin(_PIN_B_FRONTLIGHT, Pin.OUT)
led_blu = Pin(_PIN_LED_BLU_BTN, Pin.OUT)
led_red = Pin(_PIN_LED_RED_BTN, Pin.OUT)
@ -118,15 +127,16 @@ def motor_hor(*opts):
def _motorctrl(scroll: Scroll, steps: int, *opts):
end = scroll.c + steps
while True:
err = end - scroll.c
if abs(err) > 4:
speed = (err / (2 * steps)) + 0.5
scroll.speed = int(100 * speed)
else:
scroll.speed = 0
break
time.sleep_ms(5)
print(f'motorctrl, end={end}, scroll.c={scroll.c}')
#while True:
# err = end - scroll.c
# if abs(err) > 4:
# speed = (err / (2 * steps)) + 0.5
# scroll.speed = int(100 * speed)
# else:
# scroll.speed = 0
# break
# time.sleep_ms(5)
def backlight(*opts):
_fade_led(pwm_bl, *opts)
@ -167,6 +177,8 @@ def user_interaction(timeout):
b, r = btn_blu.value(), btn_red.value()
if (b + r) < 2:
tmr.deinit()
led_blu.value(0)
led_red.value(0)
return 'B' if not b else 'R'
time.sleep_ms(50)
tmr.deinit()
@ -219,6 +231,10 @@ def parseCmd(cmd_str: str):
if __name__ == '__main__':
pin_bl_a.value(1)
pin_bl_b.value(0)
pin_fl_a.value(1)
pin_fl_b.value(0)
rxData = ''
while True:
rxBuf = uart0.read(1)
@ -226,4 +242,4 @@ if __name__ == '__main__':
rxData += rxBuf.decode('utf-8')
if rxData.endswith('\n'):
parseCmd(rxData.strip())
rxData = ''
rxData = ''

View File

@ -1,14 +1,17 @@
from machine import Pin, Timer
from machine import UART, Pin, Timer
import time
led = Pin(25, Pin.OUT)
btn_blu = Pin(2, Pin.IN, Pin.PULL_UP)
btn_blu = Pin(5, Pin.IN, Pin.PULL_UP)
btn_red = Pin(3, Pin.IN, Pin.PULL_UP)
led_blu = Pin(4, Pin.OUT)
led_red = Pin(2, Pin.OUT)
def user_interaction(timeout):
def _toggle_leds(timer):
led.toggle()
led_blu.toggle()
led_red.toggle()
tmr = Timer()
tmr.init(freq=2, mode=Timer.PERIODIC, callback=_toggle_leds)
startime = time.ticks_ms()
@ -19,6 +22,8 @@ def user_interaction(timeout):
tmr.deinit()
return 'B' if not b else 'R'
tmr.deinit()
led_blu.value(0)
led_red.value(0)
return 'T' # Timeout
def recording(timeout):
@ -36,4 +41,14 @@ def recording(timeout):
return 'OK'
if __name__ == '__main__':
print(recording(20))
#print(user_interaction(20))
#Print
uart0 = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1))
rxData = ''
while True:
rxBuf = uart0.read(1)
if rxBuf is not None:
rxData += rxBuf.decode('utf-8')
if rxData.endswith('\n'):
print(rxData.strip())
rxData = ''