def __init__(self, addr, max_=None, default=0, on_update=None, on_press=None, on_release=None): self._twist = qwiic_twist.QwiicTwist(addr) self.configure(default, max_ or sys.maxint, on_update or DO_NOTHING, on_press or DO_NOTHING, on_release or DO_NOTHING) thread = threading.Thread(target=self._poll) thread.daemon = True thread.start()
def runExample(): print("\nSparkFun qwiic Twist Example 1\n") myTwist = qwiic_twist.QwiicTwist() if myTwist.connected == False: print("The Qwiic twist device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myTwist.begin() # Set the knob color to pink myTwist.set_color(100, 10, 50) while True: print("Count: %d, Pressed: %s" % (myTwist.count, \ "YES" if myTwist.pressed else "NO", \ )) time.sleep(.3)
def runExample(): print("\nSparkFun qwiic Twist Example 2 - crazy colors\n") myTwist = qwiic_twist.QwiicTwist() if myTwist.connected == False: print("The Qwiic twist device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myTwist.begin() while True: print("Count: %d, Pressed: %s" % (myTwist.count, \ "YES" if myTwist.pressed else "NO", \ )) myTwist.set_color(random.randint(0, 256), random.randint(0, 256), random.randint(0, 256)) time.sleep(.3)
def runExample(): print("\nSparkFun qwiic Twist Example 3\n") myTwist = qwiic_twist.QwiicTwist() if myTwist.connected == False: print("The Qwiic twist device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myTwist.begin() myTwist.set_color(255/2, 0, 255/2) #Set Red and Blue LED brightnesses to half of max. myTwist.connect_red = -10 # Red LED will go down 10 in brightness with each encoder tick myTwist.connect_blue = 10 #Blue LED will go up 10 in brightness with each encoder tick while True: print("Count: %d, Pressed: %s" % (myTwist.count, \ "YES" if myTwist.pressed else "NO", \ )) time.sleep(.3)
def runExample(): def toggle_mute(): global muted global orig_volume global volume if muted == False: orig_volume=volume client.volume(-volume) muted=True elif muted: client.volume(orig_volume) muted = False mute=0 global muted global orig_volume global volume muted = False reboot=False shutdown=False client = mpd.MPDClient() client.connect("localhost", 6600) myTwist = qwiic_twist.QwiicTwist() #print ( dir(myTwist) ) #print ( dir(client)) if myTwist.connected == False: print("The Qwiic twist device isn't connected to the system. Please check your connection", \ file=sys.stderr) return myTwist.begin() myTwist.set_color(112, 70, 0) #Set Red and Blue LED brightnesses to half of max. myTwist.connect_red = 5 # Red LED will go down 10 in brightness with each encoder tick myTwist.connect_green = -5 #Blue LED will go up 10 in brightness with each encoder tick myTwist.connect_blue = 2 #Blue LED will go up 10 in brightness with each encoder tick while True: mpdstatus = client.status() # Fetch volume volume = int(mpdstatus["volume"]) if myTwist.moved: diff = myTwist.get_diff() if diff > 1000 : diff = (-65536 + diff) #print("Diff :" + str(diff)) client.volume(2*diff) myTwist.clear_interrupts() myTwist.get_diff(clear_value=True) if myTwist.clicked: toggle_mute() myTwist.clear_interrupts() if myTwist.pressed: start_time = time.time() while myTwist.pressed: buttonTime = time.time() - start_time #print("Button pressed : " + str(buttonTime) + " sec" ) if .01 <= buttonTime < 2: # short push mute mute=1 elif 3 <= buttonTime < 5: print('long Press! REBOOT!') #longer push reboot reboot=True elif buttonTime >= 5: print('Looong Press! Shutdown') # really long push shutdwon reboot=False #shutdown=True myTwist.clear_interrupts() if mute == 1: toggle_mute() mute = 0 if shutdown: call(["sudo", "shutdown","-h", "now"]) if reboot: call(["sudo", "reboot"])
x_offset=53, y_offset=40, ) # Params # Screen backlight = digitalio.DigitalInOut(board.D22) backlight.switch_to_output() backlight.value = False buttonA = digitalio.DigitalInOut(board.D23) buttonB = digitalio.DigitalInOut(board.D24) buttonA.switch_to_input() buttonB.switch_to_input() # Twist twist = qwiic_twist.QwiicTwist() if twist.is_connected(): print("twist detected!") # Power button p_button = qwiic_button.QwiicButton() if p_button.is_connected(): print("power button detected!") # Keypad keypad = qwiic_keypad.QwiicKeypad() if keypad.is_connected(): print("keypad detected!") # Display height = disp.width