# main.py -- put your code here! import pyb switch = pyb.Switch() accel = pyb.Accel() while True: pyb.hid((switch(), accel.x(), -accel.y(), 0)) pyb.delay(20)
y_diff = 0 if y > up_threshold: y_diff = -(y - up_threshold) elif y < down_threshold: y_diff = -(y - down_threshold) return y_diff while True: x, y, z = accel.xyz() print((x, y, z)) #print(x, y, z) # abs_accel = math.sqrt(x**2 + y**2 + z**2) if isClicked(z): print("click!") pyb.hid((1, 0, 0, 0)) elif isReversed(z): y_diff = getRevDiff(y) pyb.hid((0, 0, 0, int(y_diff * 10))) else: x_diff, y_diff = getDiff(x, y) # if x_diff or y_diff: # print((int(x_diff*20),int(y_diff*20))) pyb.hid((0, int(x_diff * 20), int(y_diff * 25), 0)) pyb.delay(20)
print((pyb.millis() - start) // 5) # should print 3 # test udelay pyb.udelay(-1) pyb.udelay(0) pyb.udelay(1) start = pyb.millis() pyb.udelay(17000) print((pyb.millis() - start) // 5) # should print 3 # other pyb.disable_irq() pyb.enable_irq() print(pyb.freq()) print(pyb.have_cdc()) pyb.hid((0, 0, 0, 0)) # won't do anything pyb.rng() pyb.sync() print(len(pyb.unique_id())) pyb.wfi()
def osc(n, d): for i in range(n): pyb.hid((0, int(20 * math.sin(i / 10)), 0, 0)) pyb.delay(d)
# main.py -- put your code here! import pyb switch = pyb.Switch() accel = pyb.Accel() while not switch(): pyb.hid((0, -accel.x(), accel.y(), 0)) pyb.delay(20)
y_diff = 0 if y > up_threshold: y_diff = -(y - up_threshold) elif y < down_threshold: y_diff = -(y - down_threshold) return y_diff while True: x, y, z = accel.xyz() print((x, y, z)) #print(x, y, z) # abs_accel = math.sqrt(x**2 + y**2 + z**2) if isClicked(z): print("click!") pyb.hid((1, 0, 0, 0)) elif isReversed(z): y_diff = getRevDiff(y) pyb.hid((0, 0, 0, int(y_diff*10))) else: x_diff, y_diff = getDiff(x, y) # if x_diff or y_diff: # print((int(x_diff*20),int(y_diff*20))) pyb.hid((0, int(x_diff*20), int(y_diff*25), 0)) pyb.delay(20)