lcd_rows = 2 # Initialize the LCD using the pins above. 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")
from spacebrew import Spacebrew import RPi.GPIO as GPIO #Setup GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) #m1a GPIO.setup(18, GPIO.OUT) #m1b GPIO.setup(22, GPIO.OUT) #m2a GPIO.setup(23, GPIO.OUT) #m2b brew = Spacebrew("RTK-000-001", description="A Raspberry Pi with a RTK-000-001 on it", server="h1.ryanteck.org.uk") #Add the subscribers for the motors brew.addSubscriber("motor1a", "boolean") brew.addSubscriber("motor1b", "boolean") brew.addSubscriber("motor2a", "boolean") brew.addSubscriber("motor2b", "boolean") #handy string to boolean found from stack overflow def str2bool(v): return v.lower() in ("yes", "true", "t", "1") #handlers def motor1aH(value): value = str2bool(value) GPIO.output(17, value) print "motor1a" + str(value)
GPIO.output(18,0) GPIO.output(22,0) GPIO.output(23,1) def stop(): GPIO.output(17,0) GPIO.output(18,0) GPIO.output(22,0) GPIO.output(23,0) #setup Spacebrew name = "Cake" robotName = "RTK-000-003: "+ name brew = Spacebrew(robotName, server="sandbox.spacebrew.cc") brew.addSubscriber("forward", "boolean") brew.addSubscriber("backward", "boolean") brew.addSubscriber("left", "boolean") brew.addSubscriber("right", "boolean") 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()