示例#1
0
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()
	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()
示例#3
0
    # publish values
    client.publish('x', point[0])
    client.publish('y', point[1])
    client.publish('z', point[2])
    client.publish('vector', list(point))

    print('0: {:.2f} 60: {:.2f} 120: {:.2f}'.format(c000, c060, c120))
    aa = np.abs([c000, c060, c120])
    mi = np.argmin(aa)
    client.publish('000', c000 / math.pi * 1023)
    client.publish('060', c060 / math.pi * 1023)
    client.publish('120', c120 / math.pi * 1023)


try:
    with mic.recorder(samplerate=rate) as recorder:
        while True:
            data = recorder.record(numframes=1024)
            #normalize all data?
            data /= np.max(np.abs(data))
            cf = crest_factor(data)
            if cf > 5:
                print(cf)
                processC(data)
                print('processed')
except Exception as e:
    print(e)
    traceback.print_exc()
    client.stop()