lcd = jagLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight) # Print a two line message lcd.currentMessage = "Search Spotify:\n" #init spacebrew brew = Spacebrew("ttl_keyboard", description="A simple IO device", server="192.168.1.96", port=9000) brew.addPublisher("ttl_keyboard", "string") brew.addSubscriber("songTitle", "string") brew.addSubscriber("songArtist", "string") brew.subscribe("songTitle", setSongTitle) brew.subscribe("songArtist", setSongArtist) brew.start() searchString = "" #get the user's input to search on spotify while 1: c = getch.getche() print "char is " + str(ord(c)) if c: if showingSongInfo == True: lcd.clear() lcd.message("Search Spotify:\n") showingSongInfo = False lcd.message(c) searchString += c
print "motor1a" + str(value) def motor1bH(value): value = str2bool(value) GPIO.output(18, value) print "motor1b" + str(value) def motor2aH(value): value = str2bool(value) GPIO.output(22, value) print "motor2a" + str(value) def motor2bH(value): value = str2bool(value) GPIO.output(23, value) print "motor2b" + str(value) try: brew.start() brew.subscribe("motor1a", motor1aH) brew.subscribe("motor1b", motor1bH) brew.subscribe("motor2a", motor2aH) brew.subscribe("motor2b", motor2bH) finally: brew.stop() GPIO.cleanup()
def fwd_hndl(value): # do something with the value received forwards() time.sleep(0.03) stop() def bk_hndl(value): backwards() time.sleep(0.03) stop() def lt_hndl(value): left() time.sleep(0.03) stop() def rt_hndl(value): right() time.sleep(0.03) stop() brew.subscribe("forward", fwd_hndl) brew.subscribe("backward", bk_hndl) brew.subscribe("left", lt_hndl) brew.subscribe("right", rt_hndl) try: brew.start() while True: pass finally: brew.stop()