def get_flotilla(): print("connecting client...") dock = flotilla.Client() while not dock.ready: time.sleep(0.1) print("client connected!") return dock
def initializeFlotillaTouch(): try: dock = flotilla.Client(requires={'one': flotilla.Touch}) except KeyboardInterrupt: sys.exit(1) while not dock.ready: pass touch = dock.first(flotilla.Touch) return dock, touch
def read_sensors(): client = flotilla.Client() while not client.ready: pass motion = client.first(flotilla.Motion) light = client.first(flotilla.Light) colour = client.first(flotilla.Colour) weather = client.first(flotilla.Weather) vals = {} vals['motion'] = (motion.x, motion.y, motion.z) vals['light'] = light.lux r = int(colour.red / float(colour.clear) * 255) g = int(colour.green / float(colour.clear) * 255) b = int(colour.blue / float(colour.clear) * 255) vals['colour'] = (r, g, b) vals['temperature'] = weather.temperature vals['pressure'] = weather.pressure / 10.0 client.stop() return vals
def main(): print(""" Game Selection Screen Press CTRL+C to exit. """) dock = establishConnection(flotilla.Client()) matrix = getMatrix(dock) joystick = getJoystick(dock) time.sleep(1) matrix.clear() if matrix is None: print("no Matrix module found...") dock.stop() sys.exit(1) else: print("Found. Running...") select = 1 animationList = ([dancingAnimation, duckAnimation]) print_animation_cogenerator = print_animation_cogen( matrix, animationList[select]) next(print_animation_cogenerator) try: while True: print_animation_cogenerator.send(animationList[select]) if joystickX(joystick) < 0: select = (select - 1) % len(animationList) elif joystickX(joystick) > 0: select = (select + 1) % len(animationList) except KeyboardInterrupt: print("Stopping Flotilla...") dock.stop()
#!/usr/bin/env python3 import flotilla try: client = flotilla.Client() print('''Flotilla Dock Found: Version: {dock_version}'''.format(dock_version=client.dock_version)) client.stop() except AttributeError: print('Firmware version unreadable')
import sys import time import flotilla print(""" This example will show the light level on the Number display. Press CTRL + C to exit. """) # Looks for the dock, and all of the modules we need # attached to the dock so we can talk to them. dock = flotilla.Client() print("Client connected...") while not dock.ready: pass print("Finding modules...") light = dock.first(flotilla.Light) number = dock.first(flotilla.Number) if light is None or number is None: print("Some modules required were not found...") print("Make sure you have a Light and a Number module attached to the Dock!") dock.stop() sys.exit(1) else:
import flotilla print(""" This example requires a Touch and Rainbow module, you'll find these in the mini kit. Use the buttons on the Touch module to control your mood lighting! Press Ctrl+C to exit. """) client = flotilla.Client( requires={ 'one': flotilla.Touch, 'eight': flotilla.Rainbow }) def module_changed(channel, module): rainbow = client.first(flotilla.Rainbow) if module.is_a(flotilla.Touch): if module.one: rainbow.set_pixel(0,255,0,0).update() else: rainbow.set_pixel(0,0,0,0).update() #client.module_changed = module_changed while not client.ready: pass
#!/usr/bin/env python3 import flotilla import time client = flotilla.Client( requires={ 'one': flotilla.Matrix, 'eight': flotilla.Number, 'two': flotilla.Weather, 'three': flotilla.Touch, 'seven': flotilla.Light }) matrix = client.first(flotilla.Matrix) number = client.first(flotilla.Number) light = client.first(flotilla.Light) weather = client.first(flotilla.Weather) touch = client.first(flotilla.Touch) matrix.clear() number.clear() def logo(name): if name == "temp": print("temp") matrix.clear() mylistx = [ 0, 7, 1, 2, 3, 4, 5, 6, 1, 2, 5, 6, 1, 3, 4, 6, 1, 3, 4, 6, 1, 2, 5, 6, 1, 2, 3, 4, 5, 6, 0, 7
you'll find these in the mini kit. Use the buttons on the Touch module to control your mood lighting! 1 hue - 2 hue + 3 preset 4 on/off Press Ctrl+C to exit. """) try: dock = flotilla.Client(requires={ 'one': flotilla.Touch, 'two': flotilla.Rainbow }) except KeyboardInterrupt: sys.exit(1) while not dock.ready: pass touch = dock.first(flotilla.Touch) rainbow = dock.first(flotilla.Rainbow) hue = 0 lights_on = True try: while True: if touch.one:
#!/usr/bin/env python3 import time import flotilla print(""" This example uses 2 motors and increase the speed every second Easy to upgrade to use buttons or as a base for line following robot Stop this script using ctrl-c """) # Set required connections - following video client = flotilla.Client(requires={ 'six': flotilla.Motor, 'seven': flotilla.Motor }) # Wait for client while not client.ready: pass motor_left = client.channel_six motor_right = client.channel_seven # Set variables following the pimoroni sample speed = 0 try: while True: speed += 5 motor_left.speed = -speed motor_right.speed = speed
#!/usr/bin/env python3 import colorsys import time import flotilla print("Stop this script using ctrl-c") # Set required connections - following video client = flotilla.Client( requires={ 'two': flotilla.Rainbow, 'three': flotilla.Matrix, 'four': flotilla.Light, 'five': flotilla.Light, 'six': flotilla.Motor, 'seven': flotilla.Motor }) # Wait for client while not client.ready: pass # Create local variables for every component colours = { 'red': [255, 0, 0, 600], 'green': [0, 255, 0, 500], 'blue': [0, 0, 255, 1100], 'white': [255, 255, 255, 1400] } rainbow = client.channel_two
#!/usr/bin/env python3 import colorsys import time import flotilla client = flotilla.Client(requires={'eight': flotilla.Rainbow}) hue = 0 try: while True: r, g, b = [ int(x * 255.0) for x in colorsys.hsv_to_rgb(hue / 360.0, 1.0, 1.0) ] for module in client.available.values(): if module.is_a(flotilla.Rainbow): for x in range(module.num_pixels): module.set_pixel(x, r, g, b) module.update() hue += 1 hue %= 360 time.sleep(0.1) except KeyboardInterrupt: client.stop()