# 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
    #esc key (clear)
    if ord(c) == 27:
	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()
Exemple #3
0
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:
        rms = .000001
    return peak / rms