Example #1
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
Example #2
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()
Example #3
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
Example #4
0
 def switchoff():
     if verbose == True:
         print(" ")
         print("switchOff called")
     mote.clear()
     mote.show()
     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()
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()
Example #7
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")
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()
Example #9
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
Example #10
0
 def controller():
     if verbose == True:
         print(" ")
         print("controller called")
     global sunset
     global night
     global reset
     # This needs to be run threaded, or else it will block up the main thread
     while True:
         try:
             if sunset == 0:
                 reset = datetime.now() + timedelta(hours=2)
                 if verbose == True:
                     print("sunset is not set")
                     print("storing reset time as: " + str(reset))
                     print("getting time of sunset:")
                 sunset = getSunset()
                 if verbose == True:
                     print(sunset)
             current_time = datetime.now() + timedelta(hours=2)
             if current_time > (reset + timedelta(hours=24)):
                 if verbose == True:
                     print(" ")
                     print("Resetting sunset")
                 sunset = 0
             if current_time.time() > sunset:  # If we're past sunset
                 if current_time.time() < night.time(
                 ):  # And it isn't yet night
                     if verbose == True:
                         print(
                             "current time is past sunset, before night, so rainbows!"
                         )
                     rainbow()  # Bring the colours!
                 else:
                     if verbose == True:
                         print(
                             "current time is past sunset and past night, so mirror"
                         )
                     shiftingMirror()  # Otherwise, run mirror: average the
             else:  # bulbs that are on and put them on Mote
                 if verbose == True:
                     print("current time is not past sunset, so mirror")
                 shiftingMirror()
         except KeyboardInterrupt:
             if verbose == True:
                 print("exception - keyboard interrupt")
             mote.clear()
             mote.show()
             return
Example #11
0
def main():
    try:

        if args.sequence == 'sparkle':
            sparkle()
        if args.sequence == 'flash':
            flash()
        else:
            if gsentinel.good:  # otherwise we've been interrupted in a sequence
                print('sequence %s not defined.' % args.sequence)

    finally:
        motephat.clear()
        motephat.show()
        time.sleep(0.1)
Example #12
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()
Example #13
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()
Example #14
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
Example #15
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()
def main():
    mote.set_clear_on_exit(False)  # Very important
    for c in range(NUM_CHANNELS):
        mote.configure_channel(c + 1, NUM_PIXELS, True)

    current = start.copy()
    print(start)
    print(current)
    print(target)

    while current != target:
        mote.set_all(current[0], current[1], current[2])
        mote.show()

        diff = abs(current[0] - target[0])
        current[0] += (STEP if diff > STEP else
                       diff) * (-1 if current[0] > target[0] else 1)
        diff = abs(current[1] - target[1])
        current[1] += (STEP if diff > STEP else
                       diff) * (-1 if current[1] > target[1] else 1)
        diff = abs(current[2] - target[2])
        current[2] += (STEP if diff > STEP else
                       diff) * (-1 if current[2] > target[2] else 1)
        time.sleep(INTERVAL)
Example #17
0
def mote_on():
    motephat.set_all(255, 0, 0)
    motephat.show()
Example #18
0
 def clear(self):
     mote.clear()
     mote.show()
Example #19
0
 def show(self):
     mote.show()
Example #20
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
Example #21
0
 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)
     mote.clear()
Example #22
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)
Example #23
0
def mote_off():
    motephat.set_all(0, 0, 0)
    motephat.show()
def mote_update(r, g, b):
    mote.set_all(r, g, b)
    mote.show()
def main():
  mote.set_clear_on_exit(False)  # Very important
  for c in range(NUM_CHANNELS):
    mote.configure_channel(c + 1, NUM_PIXELS, True)
  mote.set_all(r, g, b)
  mote.show()
Example #26
0
def setMoteColor(r, g, b):
    # http://forums.pimoroni.com/t/mote-phat-not-all-leds-are-lighting-on-first-show/3740/3
    # Workaround: multiple motephat.show()
    motephat.set_all(r, g, b, 1.0)
    motephat.show()
    motephat.show()
def mote_off():
    mote.clear()
    mote.show()