def set_everloop_intensity(intensity): """Sets all of the LEDS to a given rgbw value""" # grab zmq context context = zmq.Context() # get socket for config config_socket = context.socket(zmq.PUSH) config_socket.connect('tcp://{0}:{1}'.format(creator_ip, creator_everloop_base_port)) # create a new driver config strut config = driver_proto.DriverConfig() # initialize an empty list for the "image" or LEDS image = [] # iterate over all 35 LEDS and set the rgbw value of each # then append it to the end of the list/image thing for led in range(35): ledValue = driver_proto.LedValue() ledValue.blue = 0 ledValue.red = 0 ledValue.green = intensity ledValue.white = 0 image.append(ledValue) # add the "image" to the config driver config.image.led.extend(image) # send a serialized string of the driver config # to the config socket config_socket.send(config.SerializeToString())
def config_gpio_read(pin): config = driver_proto.DriverConfig() # 250 miliseconds between updates. config.delay_between_updates = 0.5 # Stop sending updates 2 seconds after pings. config.timeout_after_last_ping = 3.5 config.gpio.pin = pin config.gpio.mode = driver_proto.GpioParams.INPUT sconfig.send(config.SerializeToString())
def setEverloopColor(red=0, green=0, blue=0, white=0): config = driver_proto.DriverConfig() image = [] for led in range(35): ledValue = driver_proto.LedValue() ledValue.blue = blue ledValue.red = red ledValue.green = green ledValue.white = white image.append(ledValue) config.image.led.extend(image) socket.send(config.SerializeToString())
def config_gpio_write(pin, value): """This function sets up a pin for use as an output pin""" # Create a new driver config config = driver_proto.DriverConfig() # set the pin in the config provided from the function params config.gpio.pin = pin # Set pin mode to output config.gpio.mode = driver_proto.GpioParams.OUTPUT # Set the output of the pin initially config.gpio.value = value # Send configuration to malOS using global sconfig sconfig.send(config.SerializeToString())
def send_servo_command(pin=4): # or local ip of MATRIX creator creator_ip = '127.0.0.1' creator_servo_base_port = 20013 + 32 # Set a base count of 0 count = 0 # Grab a zmq context and set it up as a push socket, then connect context = zmq.Context() socket = context.socket(zmq.PUSH) socket.connect('tcp://{0}:{1}'.format(creator_ip, creator_servo_base_port)) # Create a new driver configuration servo_config = driver_proto.DriverConfig() # Set a pin that the servo will operate on servo_config.servo.pin = pin # Start the loop of forever while True: # count mod 180 will set the angle of the servo to move to # this will change as the count increments to values of half turns angle = count % 180 # Print out the angle to stdout print('Angle: {0}'.format(angle)) # Set the servo's angle in the config servo_config.servo.angle = angle # since python isn't IO bound like node this will simulate # the event loop, updating the angle all the time but # only updating the servo every 1500000 'ticks' if count % 1500000 == 0: # Print message to stdout print('Sending new config to servo...{0}'.format(count)) # Serialize the config and send it to the driver socket.send(servo_config.SerializeToString()) # Increment the counter count += 1
def config_gpio_read(pin): """This function sets up a pin for use as an input pin""" # Create a new driver config config = driver_proto.DriverConfig() # Set 250 miliseconds between updates. config.delay_between_updates = 0.5 # Stop sending updates 2 seconds after pings. config.timeout_after_last_ping = 3.5 # Set the pin to the value provided by the function param config.gpio.pin = pin # Set the pin mode to input config.gpio.mode = driver_proto.GpioParams.INPUT # Send configuration to malOS using global sconfig sconfig.send(config.SerializeToString())
def config_socket(): """Configure and calibrate the humidity driver""" # Grab the zmq context and set it to push, then connect to it context = zmq.Context() socket = context.socket(zmq.PUSH) socket.connect('tcp://{0}:{1}'.format(creator_ip, humidity_port)) # Create a new driver config driver_config_proto = driver_proto.DriverConfig() # Set the delay between updates that the driver returns driver_config_proto.delay_between_updates = 2.0 # Stop sending updates if there is no ping for 6 seconds driver_config_proto.timeout_after_last_ping = 6.0 # Calibrate the temperature by taking a real world # measurment from a thermometer and enter it in here # in degrees celcius driver_config_proto.humidity.current_temperature = 23 # Serialize the config and send it to the config socket socket.send(driver_config_proto.SerializeToString())
# NOTE: # before run this example please execute: # pip install pyzmq protobuf # and then compile protos like this: # export SRC_DIR=../../protocol-buffers/malos # protoc -I=$SRC_DIR --python_out=./ $SRC_DIR/driver.proto import zmq import time import driver_pb2 as driver_proto creator_ip = '127.0.0.1' # or local ip of MATRIX creator creator_gpio_base_port = 20013 + 36 context = zmq.Context() socket = context.socket(zmq.PUSH) socket.connect('tcp://' + creator_ip + ':' + str(creator_gpio_base_port)) config = driver_proto.DriverConfig() config.gpio.pin = 15 config.gpio.mode = driver_proto.GpioParams.OUTPUT while True: config.gpio.value ^= 1 print ('GPIO'+str(config.gpio.pin)+'='+str(config.gpio.value)) socket.send(config.SerializeToString()) time.sleep(1)
def config_gpio_write(pin,value): config = driver_proto.DriverConfig() config.gpio.pin = pin config.gpio.mode = driver_proto.GpioParams.OUTPUT config.gpio.value = value sconfig.send(config.SerializeToString())