class Motor: def __init__(self, dc1, dc2): self.m1 = Timer(12, freq=100000).channel(1, Timer.PWM, pin=Pin('Y7'), pulse_width=0) self.dc1 = dc1 self.f1 = Pin("Y5", pyb.Pin.OUT_PP) self.b1 = Pin("Y6", pyb.Pin.OUT_PP) self.m2 = Timer(12, freq=100000).channel(2, Timer.PWM, pin=Pin('Y8'), pulse_width=0) self.dc2 = dc2 self.f2 = Pin("X20", pyb.Pin.OUT_PP) self.b2 = Pin("X19", pyb.Pin.OUT_PP) def run(self): self.b1.value(self.dc1 < 0) self.f1.value(self.dc1 > 0) self.b2.value(self.dc2 < 0) self.f2.value(self.dc2 > 0) self.m1.pulse_width_percent(abs(self.dc1)) self.m2.pulse_width_percent(abs(self.dc2))
import sensor, image, time, math from pyb import UART, Pin, Timer, LED from struct import pack, unpack import json import time led1 = LED(1) led2 = LED(2) led3 = LED(3) yellow_threshold = (100, 0, -128, 125, 16, 127) #(100, 8, -9, 127, 17, 127) quar_threshold = (100, 8, -2, 127, -6, -29) light = Timer(2, freq=50000).channel(1, Timer.PWM, pin=Pin("P6")) light.pulse_width_percent(0) # 控制亮度 0~100 #感光元件测试使用部分 sensor.reset() sensor.set_pixformat(sensor.RGB565) #初始设定后面会更改 sensor.set_framesize(sensor.QVGA) #320*240 sensor.skip_frames(time=2000) sensor.set_auto_whitebal(False) sensor.set_auto_gain(False) clock = time.clock() #######################各个数据################################## count_change = 0 change_flag = False bar_flag = False
import time from pyb import Pin, Timer # 50kHz pin6 timer2 channel1 light = Timer(2, freq=50000).channel(1, Timer.PWM, pin=Pin("P6")) light.pulse_width_percent(100) # adjust light 0~100 while (True): time.sleep(1000)
def f(): #Led 1 here performed as an indicator. pyb.LED(1).toggle() ch = Timer(2, freq=1/float(value1)).channel(10*float(value4), Timer.PWM, pin=Pin('X3')) ch.pulse_width_percent(float(value3)/(float(value2)+float(value3)))