#analog_out.value = 512 while True: counter = (counter + 1) % 256 if counter % 32 == 0: print("-------------------- analog -----------------------") str_out = "" for i in range(8): val = ss.analog_read(CRCKit_adc[i]) * 3.3 / 1024 str_out = str_out + str(round(val, 2)) + "\t" print(str_out + "\n") for i in range(4): val = ss.touch_read(i) cap_justtouched[i] = False cap_justreleased[i] = False if val > CAPTOUCH_THRESH: print("CT" + str(i + 1) + " touched! value: " + str(val)) if not cap_state[i]: cap_justtouched[i] = True cap_state[i] = True else: if cap_state[i]: cap_justreleased[i] = True
#touch_vals = (touch2.raw_value, touch3.raw_value, seesaw.touch_read(0), seesaw.touch_read(1), # seesaw.touch_read(2), seesaw.touch_read(3)) #print(touch_vals) if touch2.raw_value > 3000: print("Open jaws") pixels.fill((50, 50, 0)) IR_Command(Open) # Button A opens arms elif touch3.raw_value > 3000: print("Close jaws") pixels.fill((0, 50, 0)) IR_Command(Close) # Button B closes arms elif seesaw.touch_read(0) > CAPTOUCH_THRESH: print("Up") pixels.fill((50, 0, 50)) IR_Command(Up) elif seesaw.touch_read(1) > CAPTOUCH_THRESH: print("Down") pixels.fill((50, 50, 50)) IR_Command(Down) elif seesaw.touch_read(2) > CAPTOUCH_THRESH: print("Left") pixels.fill((50, 0, 0)) IR_Command(Left) elif seesaw.touch_read(3) > CAPTOUCH_THRESH:
# reset button A if buttona.value: while buttona.value: pass pixels.fill((0, 0, 0)) reset() if not seesaw.digital_read(TOP_SENSOR): play_file("madeit.wav") for i in range(20): rainbow() reset() #print(seesaw.touch_read(0)) #print(seesaw.touch_read(3)) if seesaw.touch_read(0) > TOUCH_THRESH: while seesaw.touch_read(0) > TOUCH_THRESH: pass last_a_time = time.monotonic() if seesaw.touch_read(3) > TOUCH_THRESH: while seesaw.touch_read(3) > TOUCH_THRESH: pass last_b_time = time.monotonic() delta_a = time.monotonic() - last_a_time delta_b = time.monotonic() - last_b_time #print("Lately... %0.1f & %0.1f" % (delta_a, delta_b)) speed = 1.0 / max(delta_a, delta_b) print("Speed %0.1f\tSteps %d" % (speed, steps))
buttonb.direction = Direction.INPUT buttonb.pull = Pull.DOWN switch = DigitalInOut(board.SLIDE_SWITCH) switch.direction = Direction.INPUT switch.pull = Pull.UP last_buttona = buttona.value last_buttonb = buttonb.value last_switch = switch.value last_touch1 = False last_touch4 = False while True: touch_vals = (seesaw.touch_read(0), seesaw.touch_read(3)) # print(touch_vals) touch1 = False if seesaw.touch_read(0) > 500: touch1 = True if touch1 != last_touch1: if touch1: start_angle = my_servo.angle end_angle = start_angle - 20 end_angle = max(0, min(end_angle, 180)) print("left from", start_angle, "to", end_angle) for a in smooth_move(start_angle, end_angle, 25): my_servo.angle = a time.sleep(0.03)
while True: counter = (counter + 1) % 256 if counter % 32 == 0: print("-------------------- analog -----------------------") str_out = "" for i in range(8): val = ss.analog_read(CRCKit_adc[i]) * 3.3/1024 str_out = str_out + str(round(val, 2)) + "\t" print(str_out + "\n") for i in range(4): val = ss.touch_read(i) cap_justtouched[i] = False cap_justreleased[i] = False if val > CAPTOUCH_THRESH: print("CT" + str(i + 1) + " touched! value: " + str(val)) if not cap_state[i]: cap_justtouched[i] = True cap_state[i] = True else: if cap_state[i]: cap_justreleased[i] = True