Example #1
0
height	  = 32

spidev	= file(dev, "wb")

# 
brew1 = SpaceBrew(("Pithon DATA BAR " + str(random.randint(0,2000))),server="sandbox.spacebrew.cc")
brew1.addPublisher("pub", "range")
brew1.addSubscriber("light", "range")

# Here's a simple example of a function that recieves a value.
def example(value):
	print "Got", value
	updateLight(value)

# We call "subscribe" to associate a function with a subscriber.
brew1.subscribe("light",example)

brew1.start()
 
column = bytearray(height * 3 + 1)
 
# Then it's a trivial matter of writing each column to the SPI port.
print "Displaying..."

def updateLight(bright):
	print "set brightness ", bright
	print "	   leds on  ", ( bright / rangeMax * height) 

	for y in range(height):
		y3 = y * 3
		newVal = 128
Example #2
0
# open serial connection
ser = serial.Serial('/dev/ttyACM0', 9600)

# create spacebrew object and add publish and subscription channels
brew1 = SpaceBrew("Pithon Example", server="sandbox.spacebrew.cc")
brew1.addPublisher("pub")
brew1.addSubscriber("light")


# Here's a simple example of a function that recieves a value.
def forwardToArduino(value):
    print "Got", value
    ser.write(pack('B', value / 4))


# We call "subscribe" to associate a function with a subscriber
brew1.subscribe("light", forwardToArduino)

# Connect to spacbrew
brew1.start()

try:
    while True:
        # Send a test string to spacbrew every 10 seconds
        brew1.publish('pub', 'bang')
        time.sleep(10)

except (KeyboardInterrupt, SystemExit) as e:
    # Calling stop on a brew disconnects it and waits for associated thread to finish.
    brew1.stop()
# open serial connection
ser = serial.Serial('/dev/ttyACM0', 9600)

# create spacebrew object and add publish and subscription channels
brew1 = SpaceBrew("Pithon Example",server="sandbox.spacebrew.cc")
brew1.addPublisher("pub")
brew1.addSubscriber("light")

# Here's a simple example of a function that recieves a value.
def forwardToArduino(value):
	print "Got",value
	ser.write(pack('B',value/4))
	
# We call "subscribe" to associate a function with a subscriber
brew1.subscribe("light",forwardToArduino)

# Connect to spacbrew
brew1.start()

try:
	while True:
		# Send a test string to spacbrew every 10 seconds
		brew1.publish('pub','bang')
		time.sleep(10)

except (KeyboardInterrupt, SystemExit) as e:
	# Calling stop on a brew disconnects it and waits for associated thread to finish.
	brew1.stop()