UIFlow Guide
This program controls the PWM signal and direction switching. Single and double presses of button A toggle the run state and direction flag. When the run flag run_flag
is 1, the PWM signal resumes and drives the device. Depending on whether the direction flag dir_flag
is 0 or 1, pin 23’s output is set to high or low to change the direction. The ADC read value monitors the input signal, and the RGB LED color indicates the running state.
from m5stack import *
from m5ui import *
from uiflow import *
from easyIO import *
import machine
dir_flag = None
run_flag = None
adc_val = None
def buttonA_wasDoublePress():
global dir_flag, run_flag, adc_val, adc0, PWM0
if dir_flag == 0:
dir_flag = 1
else:
dir_flag = 0
pass
btnA.wasDoublePress(buttonA_wasDoublePress)
def buttonA_wasPressed():
global dir_flag, run_flag, adc_val, adc0, PWM0
if run_flag == 0:
rgb.setColorAll(0x33ff33)
run_flag = 1
else:
rgb.setColorAll(0x000000)
run_flag = 0
pass
btnA.wasPressed(buttonA_wasPressed)
digitalWrite(21, 1)
digitalWrite(22, 0)
dir_flag = 0
run_flag = 0
adc0 = machine.ADC(33)
adc0.width(machine.ADC.WIDTH_12BIT)
adc0.atten(machine.ADC.ATTN_11DB)
adc_val = 0
rgb.setColorAll(0x000000)
PWM0 = machine.PWM(19, freq=12000, duty=0, timer=0)
PWM0.pause()
PWM0.duty(50)
while True:
adc_val = adc0.read()
if run_flag == 1:
PWM0.resume()
else:
PWM0.pause()
if dir_flag == 1:
digitalWrite(23, 1)
else:
digitalWrite(23, 0)
print(adc_val)
wait_ms(2)
stepmotor = Stepmotor('Full')
stepmotor.disable()
stepmotor.enable()
stepmotor.get_status()
stepmotor.get_voltage()
stepmotor.move_circles(0, 0)
stepmotor.move_steps(0, 0)
stepmotor.reset()