#Motor Side spacebrewServer = "h1.ryanteck.org.uk" spacebrewPort = 9000 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)
def right(): GPIO.output(17,1) 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()
# Define LCD column and row size for 16x2 LCD. lcd_columns = 16 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:
import math import soundcard as sc import numpy as np import scipy.signal from matplotlib.mlab import rms_flat from spacebrew import Spacebrew import traceback rate = 96000 soundSpeed = 343 # m/s client = Spacebrew('mic_array', server='localhost') client.addPublisher('000', 'range') client.addPublisher('060', 'range') client.addPublisher('120', 'range') client.addPublisher('x', 'number') client.addPublisher('y', 'number') client.addPublisher('z', 'number') client.addPublisher('vector', 'vector3') client.start() # open the mic array mic = sc.get_microphone('Azure Kinect') def crest_factor(signal): """ Crest factor of a 1D signal """ peak = np.amax(np.absolute(signal)) rms = rms_flat(signal) if rms == 0: