Beispiel #1
0
 def switchoff():
     if verbose == True:
         print(" ")
         print("switchOff called")
     mote.clear()
     mote.show()
     return
Beispiel #2
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
Beispiel #3
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()
Beispiel #4
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)
Beispiel #5
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()
Beispiel #6
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
Beispiel #7
0
        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()
        mote.show()
        time.sleep(10)
        x += 1
else:
Beispiel #8
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)
def mote_off():
    mote.clear()
    mote.show()
Beispiel #10
0
 def clear(self):
     mote.clear()
     mote.show()