示例#1
0
 def set_colour(self, r, g, b):
   MAX_CHANNELS = 4
   MAX_PIXELS = 16
   for channel in range(MAX_CHANNELS):
     for pixel in range(MAX_PIXELS):
       motephat.set_pixel(channel + 1, pixel, r, g, b)
   motephat.show()
def set_all():
    for c in range(NUM_CHANNELS):
        for p in range(0, len(json_arr)):
            pixel_arr = json_arr[p]
            mote.set_pixel(c + 1, p, int(pixel_arr[0]), int(pixel_arr[1]),
                           int(pixel_arr[2]))
    mote.show()
示例#3
0
def mote_off(status):
    for chan in range(1, 5):
        if status['state'][chan] == 0:
            for pixel in range(16):
                motephat.set_pixel(chan, pixel, 0, 0, 0)
    motephat.show()
    return True
示例#4
0
 def setAll(r, g, b, seq):
     if verbose == True:
         print(" ")
         print("setAll called")
         print("colour is r=" + str(r) + " g=" + str(g) + " b=" + str(b))
     # Set all pixels to hue_1
     if seq == True:
         for channel in range(4):
             for pixel in range(16):
                 mote.set_pixel(channel + 1, pixel, r, g, b)
                 if anythingOn == False:
                     switchoff()
                     break
                 else:
                     mote.show()
     if seq == False:
         for channel in range(4, -1, -1):
             for pixel in range(16, -1, -1):
                 mote.set_pixel(channel + 1, pixel, r, g, b)
                 if anythingOn == False:
                     switchoff()
                     break
                 else:
                     mote.show()
     if verbose == True:
         print("sleeping 5 seconds")
     time.sleep(5)
     return
def mote_on():
    for channel in range(4):
        for pixel in range(16):
            mote.set_pixel(channel + 1, pixel, 255,255,255, 0.7)
        time.sleep(0.01)

    mote.show()
示例#6
0
 def set_pixel(self, x, y, r, g, b):
     r, g, b = self.apply_correction(r, g, b)
     if self.vertical:
         mote.set_pixel(x, y, r, g, b)
     else:
         channel = x // self.pixels
         pixel = x % self.pixels
         mote.set_pixel(channel, pixel, r, g, b)
def mote_change(c):
    r,g,b = hex_to_rgb(c)
    print(r,g,b)
    for channel in range(4):
        for pixel in range(16):
            mote.set_pixel(channel + 1, pixel, r,g,b, 0.5)
        time.sleep(0.01)

    mote.show()
示例#8
0
def mote_on(status):
    for chan in range(4):
        r, g, b = status['colour'][chan + 1]
        for pixel in range(16):
            if not status['state'][chan + 1] == 0:
                motephat.set_pixel(chan + 1, pixel, r, g, b)
            else:
                motephat.set_pixel(chan + 1, pixel, 0, 0, 0)
    motephat.show()
    return True
示例#9
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()
示例#10
0
def sparkle():
    while gsentinel.good:
        pix1s = sample(range(16), randint(0, args.density))
        pix2s = sample(range(16), randint(0, args.density))
        c = randomise_colours()
        for cpix in pix1s:
            if not args.keepcolour:
                c = randomise_colours()
            motephat.set_pixel(1, cpix, c[0], c[1], c[2])
            motephat.show()
        for cpix in pix2s:
            if not args.keepcolour:
                c = randomise_colours()
            motephat.set_pixel(2, cpix, c[0], c[1], c[2])
            motephat.show()
        time.sleep(args.interval)
        motephat.clear()
示例#11
0
 def rainbow():
     if verbose == True:
         print(" ")
         print("rainbow called")
     current_time = datetime.now().time()
     while current_time < night.time():
         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)
         current_time = datetime.now().time()
示例#12
0
def flash():
    alt = 0  # toggle between 0 and 1 to alternate flashing pixels
    while gsentinel.good:
        pixlist = range(0 + alt, 16 + alt, 2)
        c = randomise_colours()
        for cpix in pixlist:
            if not args.keepcolour:
                c = randomise_colours()
            motephat.set_pixel(1, cpix, c[0], c[1], c[2])
            motephat.set_pixel(2, cpix, c[0], c[1], c[2])
        motephat.show()
        time.sleep(args.interval)
        motephat.clear()
        motephat.show()
        time.sleep(args.interval)
        if alt == 0:
            alt = 1
        else:
            alt = 0
示例#13
0
    def fader(start_hue, end_hue, add_direction, steps, seq):
        if verbose == True:
            print(" ")
            print("fader called")
            print("start_hue is " + str(start_hue))
            print("end_hue is " + str(end_hue))
        if anythingOn == True:
            # Set silly verbose vars and move hue one step away from hue
            if add_direction == True:
                direction = "clockwise"  # Going clockwise
                hue = (start_hue - steps) % 360  # Move a step away from hue
            else:
                direction = "anticlockwise"  # Going anticlockwise
                hue = (start_hue + steps) % 360  # Move a step away from hue

            if verbose == True:
                print(" ")
                print("going from start_hue to end_hue " + direction)

        if anythingOn == True:
            # Loop to fade from start_hue to end_hue
            x = 0
            hue = start_hue
            if seq == True:
                while x < 65:
                    for channel in range(4):
                        for pixel in range(16):
                            if add_direction == True:
                                hue = (hue + steps) % 360
                            else:
                                hue = (hue - steps) % 360
                            colour = hsv_to_rgb(hue / 360.0, 1.0, 1.0)
                            r = int(colour[0] * 255)
                            g = int(colour[1] * 255)
                            b = int(colour[2] * 255)
                            if ultra_verbose == True:
                                print("set c" + str(channel + 1) + "p" +
                                      str(pixel) + " to hue " +
                                      str(hue % 360) + " or r=" + str(r) +
                                      " g=" + str(g) + " b=" + str(b))
                            if anythingOn == False:
                                switchoff()
                                break
                            else:
                                # Set each pixel one by one to the appropriate colour
                                mote.set_pixel(channel + 1, pixel, r, g, b)
                                mote.show()
                                x += 1
                                time.sleep(0.01)
            if seq == False:
                while x < 65:
                    for channel in range(4, -1, -1):
                        for pixel in range(16, -1, -1):
                            if add_direction == True:
                                hue = (hue + steps) % 360
                            else:
                                hue = (hue - steps) % 360
                            colour = hsv_to_rgb(hue / 360.0, 1.0, 1.0)
                            r = int(colour[0] * 255)
                            g = int(colour[1] * 255)
                            b = int(colour[2] * 255)
                            if ultra_verbose == True:
                                print("set c" + str(channel + 1) + "p" +
                                      str(pixel) + " to hue " +
                                      str(hue % 360) + " or r=" + str(r) +
                                      " g=" + str(g) + " b=" + str(b))
                            if anythingOn == False:
                                switchoff()
                                break
                            else:
                                # Set each pixel one by one to the appropriate colour
                                mote.set_pixel(channel + 1, pixel, r, g, b)
                                mote.show()
                                x += 1
                                time.sleep(0.01)

            if verbose == True:
                print("fade from start_hue to end_hue complete")
                print("setting all pixels to end_hue, " + str(hue) +
                      ", or r=" + str(r) + " g=" + str(g) + " b=" + str(b))

        if anythingOn == True:
            seq = not seq
            setAll(r, g, b, seq)

        return
示例#14
0
 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()
         time.sleep(0.01)
     print("rainbow time over")
     print("lights out - clear and show - for 10 seconds")
     mote.clear()
     mote.show()
     time.sleep(10)
     print("lights on for 10 seconds")
     for channel in channels:
         for pixel in range(16):
             mote.set_pixel(channel, pixel, 150, 150, 150)
     mote.show()
     time.sleep(10)
     print("lights out - set 0 bright and clear - for 10 seconds")
     mote.set_brightness(0)
示例#15
0
print("""Rainbow

Press Ctrl+C to clear and exit.
""")

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

h = 1

try:
    while True:
        for channel in range(1, 5):
            pixel_count = mote.get_pixel_count(channel)
            for pixel in range(pixel_count):
                hue = (h + ((channel - 1) * pixel_count * 5) +
                       (pixel * 5)) % 360
                r, g, b = [
                    int(c * 255) for c in hsv_to_rgb(hue / 360.0, 1.0, 1.0)
                ]
                mote.set_pixel(channel, pixel, r, g, b)
        mote.show()
        time.sleep(0.05)

except KeyboardInterrupt:
    mote.clear()
    mote.show()
示例#16
0
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]

        print(f)

        channel = 1
        for col in f:
            col = col['field2']
            r, g, b = tuple(ord(c) for c in col[1:].lower().decode('hex'))
            for pixel in range(motephat.get_pixel_count(channel)):
                motephat.set_pixel(channel, pixel, r, g, b)
            channel += 1

        motephat.show()

        time.sleep(5)

except KeyboardInterrupt:
    motephat.clear()
    motephat.show()
    time.sleep(0.1)
示例#17
0
#!/usr/bin/env python

import colorsys
import math
import time
from random import randint

import motephat

motephat.set_brightness(1)

try:
    while True:
        cpix = randint(0,15)
        cchn = randint(1,2)
        br = randint(55,255)
        motephat.set_pixel(cchn, cpix, br, br, br)
        motephat.show()
	time.sleep(0.1)
        motephat.set_pixel(cchn, cpix, 0, 0, 0)
        motephat.show()

except KeyboardInterrupt:
    motephat.clear()
    motephat.show()
    time.sleep(0.1)
示例#18
0
#!/usr/bin/env python

import colorsys
import math
import time

import motephat


motephat.set_brightness(1)

while True:
    br = (math.sin(time.time()) + 1) / 2
    br *= 255.0
    br = int(br)

    for channel in range(1,5):
        for pixel in range(16):
            motephat.set_pixel(channel, pixel, br, br, br)

    motephat.show()