diff --git a/micropizza/main.py b/micropizza/main.py index 5805111..edf01b0 100644 --- a/micropizza/main.py +++ b/micropizza/main.py @@ -6,12 +6,12 @@ _PWM_MAX = const(65535) _PWM_FREQ = const(2000) _PIN_EN_MOTOR_VERT = const(14) -_PIN_A_MOTOR_VERT = const(13) -_PIN_B_MOTOR_VERT = const(12) +_PIN_A_MOTOR_VERT = const(12) +_PIN_B_MOTOR_VERT = const(13) _PIN_EN_MOTOR_HOR = const(15) -_PIN_A_MOTOR_HOR = const(11) -_PIN_B_MOTOR_HOR = const(10) +_PIN_A_MOTOR_HOR = const(10) +_PIN_B_MOTOR_HOR = const(11) _PIN_EN_BACKLIGHT = const(17) _PIN_A_BACKLIGHT = const(18) @@ -26,10 +26,10 @@ _PIN_LED_BLU_BTN = const(4) _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 @@ -94,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) @@ -122,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) @@ -171,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() @@ -223,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) @@ -230,4 +242,4 @@ if __name__ == '__main__': rxData += rxBuf.decode('utf-8') if rxData.endswith('\n'): parseCmd(rxData.strip()) - rxData = '' \ No newline at end of file + rxData = '' diff --git a/micropizza/test.py b/micropizza/test.py index e822fcc..2e37ddf 100644 --- a/micropizza/test.py +++ b/micropizza/test.py @@ -1,4 +1,4 @@ -from machine import Pin, Timer +from machine import UART, Pin, Timer import time led = Pin(25, Pin.OUT) @@ -41,5 +41,14 @@ def recording(timeout): return 'OK' if __name__ == '__main__': - print(user_interaction(20)) - #print(recording(20)) \ No newline at end of file + #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 = '' \ No newline at end of file