Example #1
0
 def set_brightness(self, val):
     val = int(val)
     if 0 <= val <= 255:
         mote.set_brightness(
             val / 255)  # Set brightness through unicornhat library
         self.brightness = val  # Log user-selected brightness to a variable
         mote.show()
     else:
         logging.error("Brightness must be between 0 and 255")
Example #2
0
def updateState(data):
    t_end = time.time() + 10
    squares = data['squares']
    count = 0

    mote.configure_channel(1, 16, False)
    mote.configure_channel(2, 16, False)
    mote.configure_channel(3, 16, False)
    mote.configure_channel(4, 16, False)
    mote.set_brightness(0.1)

    for square in squares:
        if square['isSelected']:
            count += 1
    print(count)

    while time.time() < t_end:

        # easter egg! if all 64 are lit, then rainbow party!
        if count == 64:
            h = time.time() * 50
            for channel in range(4):
                for pixel in range(16):
                    hue = (h + (channel * 64) + (pixel * 4)) % 360
                    r, g, b = [
                        int(c * 255)
                        for c in hsv_to_rgb(hue / 360.0, 1.0, 1.0)
                    ]
                    mote.set_pixel(channel + 1, pixel, r, g, b)
            mote.show()
            time.sleep(0.01)
        else:
            # lights go from left to right
            for pixel in reversed(range(16)):
                mote.clear()
                mote.set_pixel(1, pixel, random.randint(0, 255),
                               random.randint(0, 255), random.randint(0, 255))
                mote.set_pixel(2, pixel, random.randint(0, 255),
                               random.randint(0, 255), random.randint(0, 255))
                mote.set_pixel(3, pixel, random.randint(0, 255),
                               random.randint(0, 255), random.randint(0, 255))
                mote.set_pixel(4, pixel, random.randint(0, 255),
                               random.randint(0, 255), random.randint(0, 255))
                mote.show()
                time.sleep(0.02)
            mote.show()

    mote.clear()
    mote.show()
Example #3
0
if ultra_verbose == "True":
    ultra_verbose = True
else:
    ultra_verbose = False

debug = getenv('DEBUG')
if debug == "True":
    debug = True
else:
    debug = False

if debug == True:
    print("debug mode active")
    print("this will loop five times and then stop")
    channels = [0, 1, 2, 3]
    mote.set_brightness(0.2)
    x = 0
    while x < 5:
        print("doing a rainbow for 10 seconds")
        current_time = datetime.now()
        while datetime.now() < (current_time + timedelta(seconds=10)):
            h = time.time() * 50
            for channel in range(4):
                for pixel in range(16):
                    hue = (h + (channel * 64) + (pixel * 4)) % 360
                    r, g, b = [
                        int(c * 255)
                        for c in hsv_to_rgb(hue / 360.0, 1.0, 1.0)
                    ]
                    mote.set_pixel(channel + 1, pixel, r, g, b)
            mote.show()
Example #4
0
except ImportError:
    exit("""This script requires the requests module.
Install with: sudo pip install requests""")

import motephat

print("""
Mote pHAT: Cheerlights

Display colours from the cheerlights API.

Press Ctrl+C to exit!

""")

motephat.set_brightness(1)

num_pixels = 16

motephat.configure_channel(1, num_pixels, False)
motephat.configure_channel(2, num_pixels, False)
motephat.configure_channel(3, num_pixels, False)
motephat.configure_channel(4, num_pixels, False)

try:
    while True:
        r = requests.get('http://api.thingspeak.com/channels/1417/feed.json')
        j = r.json()
        f = j['feeds'][-8:]

        f = [element for index, element in enumerate(f) if index % 2 == 0]
Example #5
0
 def setup(self):
   motephat.set_brightness(1)
   motephat.set_clear_on_exit(True)