Compare commits
No commits in common. "761e0f6c8d1f63863f6326533024beff663d783d" and "c54301d14ecf55d4add6e9fb344072b8dfa56327" have entirely different histories.
761e0f6c8d
...
c54301d14e
2 changed files with 31 additions and 62 deletions
|
@ -5,31 +5,27 @@ import time
|
|||
_PWM_MAX = const(65535)
|
||||
_PWM_FREQ = const(2000)
|
||||
|
||||
_PIN_EN_MOTOR_VERT = const(14)
|
||||
_PIN_A_MOTOR_VERT = const(12)
|
||||
_PIN_B_MOTOR_VERT = const(13)
|
||||
_PIN_EN_MOTOR_VERT = const(0)
|
||||
_PIN_A_MOTOR_VERT = const(0)
|
||||
_PIN_B_MOTOR_VERT = const(0)
|
||||
|
||||
_PIN_EN_MOTOR_HOR = const(15)
|
||||
_PIN_A_MOTOR_HOR = const(10)
|
||||
_PIN_B_MOTOR_HOR = const(11)
|
||||
_PIN_EN_MOTOR_HOR = const(0)
|
||||
_PIN_A_MOTOR_HOR = const(0)
|
||||
_PIN_B_MOTOR_HOR = 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_EN_BACKLIGHT = const(0)
|
||||
_PIN_EN_FRONTLIGHT = const(0)
|
||||
|
||||
_PIN_LED_RED_BTN = const(2)
|
||||
_PIN_LED_BLU_BTN = const(4)
|
||||
_PIN_LED_RED_BTN = const(0)
|
||||
_PIN_LED_BLU_BTN = const(0)
|
||||
|
||||
_PIN_RED_BTN = const(3)
|
||||
_PIN_BLU_BTN = const(5)
|
||||
_PIN_RED_BTN = const(0)
|
||||
_PIN_BLU_BTN = 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)
|
||||
_PIN_SENS_END_VERT = const(0)
|
||||
_PIN_SENS_CNT_VERT = const(0)
|
||||
_PIN_SENS_END_HOR = const(0)
|
||||
_PIN_SENS_CNT_HOR = const(0)
|
||||
|
||||
CMD_MOT_V = 'V' # run vertical motor
|
||||
CMD_MOT_H = 'H' # run horizontal motor
|
||||
|
@ -94,12 +90,7 @@ 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.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)
|
||||
pin_mh_b = Pin(_PIN_B_MOTOR_HOR)
|
||||
|
||||
led_blu = Pin(_PIN_LED_BLU_BTN, Pin.OUT)
|
||||
led_red = Pin(_PIN_LED_RED_BTN, Pin.OUT)
|
||||
|
@ -127,16 +118,15 @@ def motor_hor(*opts):
|
|||
|
||||
def _motorctrl(scroll: Scroll, steps: int, *opts):
|
||||
end = scroll.c + steps
|
||||
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)
|
||||
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)
|
||||
|
@ -177,8 +167,6 @@ 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()
|
||||
|
@ -231,10 +219,6 @@ 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)
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
from machine import UART, Pin, Timer
|
||||
from machine import Pin, Timer
|
||||
import time
|
||||
|
||||
led = Pin(25, Pin.OUT)
|
||||
|
||||
btn_blu = Pin(5, Pin.IN, Pin.PULL_UP)
|
||||
btn_blu = Pin(2, 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_blu.toggle()
|
||||
led_red.toggle()
|
||||
led.toggle()
|
||||
tmr = Timer()
|
||||
tmr.init(freq=2, mode=Timer.PERIODIC, callback=_toggle_leds)
|
||||
startime = time.ticks_ms()
|
||||
|
@ -22,8 +19,6 @@ 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):
|
||||
|
@ -41,14 +36,4 @@ def recording(timeout):
|
|||
return 'OK'
|
||||
|
||||
if __name__ == '__main__':
|
||||
#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 = ''
|
||||
print(recording(20))
|
Loading…
Reference in a new issue