Beispiel #1
0
 def runway(self):
     blinkt.set_all(0, 0, 0)
     blinkt.show()
     self._running = True
     blinkt.set_pixel(4,255,255,0)
     blinkt.show()
     blinkt.set_pixel(4,0,0,0)
     blinkt.show()
     blinkt.set_pixel(3,255,255,0)
     blinkt.show()
     blinkt.set_pixel(3,0,0,0)
     blinkt.show()
     blinkt.set_pixel(2,255,255,0)
     blinkt.show()
     blinkt.set_pixel(2,0,0,0)
     blinkt.show()
     time.sleep(0.04)
     while self._running:
         for i in range(8):
             blinkt.clear()
             blinkt.set_pixel(i, 119, 255, 0)
             blinkt.show()
             blinkt.time.sleep(0.05)
     print("Runway LED thread ended...")
     blinkt.set_all(0, 0, 0)
     blinkt.show()
Beispiel #2
0
 def show_colour(self, colour):
     if colour in self.colours.keys():
         c = self.get_colour(colour)
         blinkt.set_pixel(self.pixel, c.r, c.g, c.b)
     else:
         blinkt.clear()
     blinkt.show()
Beispiel #3
0
def sigterm_handler(signal, frame):
    # save the state here or do whatever you want
    # quit
    print "signal received, quitting pinger.py"
    clear()
    show()
    sys.exit(0)
    def run(self):
        start = 0
        end = 60

        while self.running:
            wait = np.random.choice(np.random.noncentral_chisquare(5, 1, 1000),
                                    1)[0] / 50
            n = np.random.choice(np.random.noncentral_chisquare(5, 0.1, 1000),
                                 1)
            limit = int(n[0])

            if limit > blinkt.NUM_PIXELS:
                limit = blinkt.NUM_PIXELS

            for pixel in range(limit):
                hue = start + ((
                    (end - start) / float(blinkt.NUM_PIXELS)) * pixel)
                r, g, b = [
                    int(c * 255)
                    for c in colorsys.hsv_to_rgb(hue / 360.0, 1.0, 1.0)
                ]
                blinkt.set_pixel(pixel, r, g, b)
                blinkt.show()
                time.sleep(0.05 / (pixel + 1))

            time.sleep(wait)
            blinkt.clear()
Beispiel #5
0
def custom_alert(r, g, b, current_status):
    """Consistent pulse"""
    clear()
    brightness = 0.0
    direction = True
    running = True
    while running:
        if direction:
            brightness += 0.1
            if brightness >= 0.9:
                direction = False
        else:
            if brightness > 0.15:
                brightness -= 0.1
            else:
                brightness = 0.0
            if brightness <= 0.000001:
                direction = True
        set_all(r, g, b, brightness)
        show()
        if brightness == 0.0:
            custom_sleep(0.3, current_status)
        elif brightness >= 0.9:
            custom_sleep(0.3, current_status)
        else:
            custom_sleep(0.05, current_status)
Beispiel #6
0
def fb_attack(channel):
    global fb
    fb['running'] = True
    print("BANG!")
    blinkt.clear()
    os.system('sudo sh /home/pi/FistBump/wpa_hashgrab.sh')
    exit()
Beispiel #7
0
def rainbow(runSeconds: int = 5, clear: bool = True, decreaseBrightness: bool = False):
  spacing = 360.0 / 8.0
  hue = 0

  blinkt.set_clear_on_exit()

  start_time = datetime.datetime.now()

  tSeconds = (datetime.datetime.now() - start_time).total_seconds()

  while (tSeconds < runSeconds) :
    hue = int(time.time() * 100) % 360

    for x in range(blinkt.NUM_PIXELS):
      offset = x * spacing
      h = ((hue + offset) % 360) / 360.0
      r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)]
      blinkt.set_pixel(x, r, g, b)

    brightness = math.ceil((tSeconds/runSeconds)*10)/10

    if(decreaseBrightness):
      brightness = 1 - brightness

    blinkt.set_brightness(brightness)

    blinkt.show()
    time.sleep(0.005)
    tSeconds = (datetime.datetime.now() - start_time).total_seconds()

  if clear:
    blinkt.clear()
    blinkt.show()
    def run(self):
        on_value = 64
        
        while self.running:
            t = localtime()
            h, m, s = t.tm_hour, t.tm_min, t.tm_sec

            print("{h}:{m}:{s}".format(h=h, m=m, s=s))

            blinkt.clear()

            # Blink LED 0
            c = on_value * (s % 2)
            blinkt.set_pixel(0, c, c, c)

            for n in range(6):
                # Grab the n'th bit from hour, min and second
                bit_h = (h & (1 << n)) > 0
                bit_m = (m & (1 << n)) > 0
                bit_s = (s & (1 << n)) > 0

                r, g, b = [int(c * on_value) for c in (bit_h, bit_m, bit_s)]

                blinkt.set_pixel(7 - n, r, g, b)

            blinkt.set_brightness(self.brightness)
            blinkt.show()

            sleep(1)
Beispiel #9
0
def light_red():
    
    #timer ia used to work out how long the larson style effect lasts and
    #countred keeps a count of the total calls to this function.
    
    Display.Clear()
    timer = 0
    global countred
    countred = countred + 1
    
    #The 4 digit display python function needs the digits formatted as a 4 item array
    #So here we make it at least 4 digits and then split it into a 4 length array
    
    redformat = f'{countred:04}'
    redarray = list(redformat)
    #print(redarray)
    redarraynumbers = [int(x) for x in redarray]
    #print('Red Hits: ' + str(countred))
    while timer < 15:
        timer = timer + 1
        #This section is almost a carbon copy of the example provided by Pimoroni
        delta = (time.time() - start_time) * 8
        offset = int(round(((math.sin(delta) + 1) / 2) * (blinkt.NUM_PIXELS - 1)))
    
        for i in range(blinkt.NUM_PIXELS):
            blinkt.set_pixel(i , LEDBRIGHT[offset + i], 0, 0)

        blinkt.show()

        time.sleep(0.01)
    blinkt.clear()
    blinkt.show()
    Display.Show(redarraynumbers)
Beispiel #10
0
def restart():
    cmd = 'pkill -f --signal SIGQUIT app.py'
    os.system(cmd)
    blinkt.clear()
    blinkt.show()

    subprocess.call(['python ' '~/iot-example/app.py'], shell=True)
Beispiel #11
0
def setPixels(r, g, b, brightness=0.1):
    global globalBrightness, globalBlue, globalGreen, globalRed

    globalRed = r
    globalGreen = g
    globalBlue = b

    if brightness is not None:
        globalBrightness = brightness
        blinkt.set_brightness(brightness)
    else:
        brightness = 0.1

    blinkt.clear()
    pixels = []
    if r == 0 and g == 144 and b == 0:
        pixels = [0, 2, 4, 6]
    elif r == 255 and g == 160 and b == 0:
        pixels = [0, 2, 4, 6]
    elif r == 179 and g == 0 and b == 0:
        pixels = [0, 1, 3, 4, 6, 7]
    elif r == 149 and g == 0 and b == 0:
        pixels = [0, 1, 2, 3, 4, 5, 6, 7]
    else:
        pixels = [1]

    for val in pixels:
        blinkt.set_pixel(val, r, g, b, brightness)
    blinkt.show()
Beispiel #12
0
def blinkt_morse(morse_code_list):
    for morse_code in morse_code_list:
        time.sleep(2)
        listed_morse_code = list(morse_code)
        for symbol in listed_morse_code:
            if symbol == '.':
                clear()
                set_all(255, 255, 255)
                show()
                time.sleep(1)
                clear()
                set_all(0, 0, 0)
                show()
                time.sleep(0.5)
            elif symbol == '_':
                clear()
                show()
                time.sleep(7)
            else:
                clear()
                set_all(255, 255, 255)
                show()
                time.sleep(3)
                clear()
                set_all(0, 0, 0)
                show()
                time.sleep(0.5)
Beispiel #13
0
def show_led(led_num, led_colour, delay):
    r, g, b = led_colour
    blinkt.clear()
    blinkt.set_brightness(0.1)
    blinkt.set_pixel(led_num, r, g, b)
    blinkt.show()
    time.sleep(d)
Beispiel #14
0
def play_sound(filename):
    color_provider = ColorProvider(20)

    f = wave.open(filename, 'rb')

    periodsize = int(f.getframerate() / 16)
    print("framerate: %f, periodsize: %f" % (f.getframerate(), periodsize))
    data = f.readframes(periodsize)

    period_length = 1 / 16
    counter = 1

    next_timestamp = time.time()

    while data:
        if time.time() >= next_timestamp:
            device.write(data)
            next_timestamp = time.time() + period_length
            vu = (math.log(float(max(audioop.max(data, 2), 1))) -
                  log_lo) / (log_hi - log_lo)
            volume = (min(max(int(vu * 100), 0), 100))
            print("%i: %f" % (counter, volume))
            r, g, b = color_provider.give_color()
            blinkt.set_all(r, g, b, brightness=volume / 200.0)
            blinkt.show()
            counter += 1
            data = f.readframes(periodsize)
    f.close()
    blinkt.clear()
    blinkt.show()
def eyes_left(seconds, r, g, b):
    blinkt.clear()
    blinkt.set_pixel(0, r, g, b)
    blinkt.set_pixel(5, r, g, b)
    sleep(seconds)
    blinkt.clear()
    sleep(0.2)
Beispiel #16
0
def light_blue():
    Display.Clear()
    timer = 0
    global countblue
    countblue = countblue + 1
    
    blueformat = f'{countblue:04}'
    bluearray = list(blueformat)
    #print(bluearray)

    bluearraynumbers = [int(x) for x in bluearray]
    #print('Blue Hits: ' + str(countblue))

    while timer < 15:
        timer = timer + 1
        delta = (time.time() - start_time) * 8
        offset = int(round(((math.sin(delta) + 1) / 2) * (blinkt.NUM_PIXELS - 1)))
    
        for i in range(blinkt.NUM_PIXELS):
            blinkt.set_pixel(i , 0, 0, LEDBRIGHT[offset + i])

        blinkt.show()

        time.sleep(0.01)
    blinkt.clear()
    blinkt.show()

    Display.Show(bluearraynumbers)
def eyes_right(seconds, r, g, b):
    blinkt.clear()
    blinkt.set_pixel(2, r, g, b)
    blinkt.set_pixel(7, r, g, b)
    sleep(seconds)
    blinkt.clear()
    sleep(0.2)
Beispiel #18
0
def light_green():
    Display.Clear()
    timer = 0
    global countgreen
    countgreen = countgreen + 1
    
    greenformat = f'{countgreen:04}'
    greenarray = list(greenformat)
    #print(greenarray)

    greenarraynumbers = [int(x) for x in greenarray]
    #print('Green Hits: ' + str(countgreen))

    while timer < 15:
        timer = timer + 1
        delta = (time.time() - start_time) * 8
        offset = int(round(((math.sin(delta) + 1) / 2) * (blinkt.NUM_PIXELS - 1)))
    
        for i in range(blinkt.NUM_PIXELS):
            blinkt.set_pixel(i , 0, LEDBRIGHT[offset + i], 0) 

        blinkt.show()

        time.sleep(0.01)
    blinkt.clear()
    blinkt.show()

    Display.Show(greenarraynumbers)
Beispiel #19
0
def set_green():
    blinkt.clear()
    blinkt.set_brightness(.1)
    blinkt.set_pixel(0, 0, 255, 0)
    time.sleep(1)
    blinkt.show()
    blinkt.set_pixel(1, 0, 255, 0)
    time.sleep(1)
    blinkt.show()
    blinkt.set_pixel(2, 0, 255, 0)
    time.sleep(1)
    blinkt.show()
    blinkt.set_pixel(3, 0, 255, 0)
    time.sleep(1)
    blinkt.show()
    blinkt.set_pixel(4, 0, 255, 0)
    time.sleep(1)
    blinkt.show()
    blinkt.set_pixel(5, 0, 255, 0)
    time.sleep(1)
    blinkt.show()
    blinkt.set_pixel(6, 0, 255, 0)
    time.sleep(1)
    blinkt.show()
    blinkt.set_pixel(7, 0, 255, 0)
    time.sleep(1)
    blinkt.show()
Beispiel #20
0
def show(r, g, b):
    blinkt.set_brightness(0.05)
    blinkt.set_all(r, g, b)
    blinkt.show()
    time.sleep(2)
    blinkt.clear()
    blinkt.show()
Beispiel #21
0
def colorrotate(runSeconds: int = 5, clear: bool = True, decreaseBrightness: bool = False):
  hue = 0

  blinkt.set_clear_on_exit()

  start_time = datetime.datetime.now()

  tSeconds = (datetime.datetime.now() - start_time).total_seconds()

  while (tSeconds < runSeconds) :
    brightness = math.ceil((tSeconds/runSeconds)*10)/10

    if(decreaseBrightness):
      brightness = 1 - brightness

    hue = int(time.time() * 100) % 360
    h = (hue % 360) / 360.0
    r, g, b = [int(c * 255) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)]
    blinkt.set_all(r, g, b, brightness)

    blinkt.show()
    time.sleep(0.005)
    tSeconds = (datetime.datetime.now() - start_time).total_seconds()

  if clear:
    blinkt.clear()
    blinkt.show()
Beispiel #22
0
    def run(self):

        self._running = True

        print("Showing Blinkt Attract")

        blinkt.clear()
        blinkt.show()

        while True:

            try:
                for j in range(0, 8, 1):

                    if self._running == False:
                        print("Exitting Show Blinkt Attract")
                        clearBlinkt()
                        return

                    set_pixel(j, 255, 0, 0, 0.1)
                    blinkt.show()
                    time.sleep(0.05)

                for j in range(0, 7, 1):

                    if self._running == False:
                        print("Exitting Show Blinkt Attract")
                        clearBlinkt()
                        return

                    set_pixel(j, 0, 0, 0, 0.1)
                    blinkt.show()
                    time.sleep(0.05)

                for j in range(7, -1, -1):

                    if self._running == False:
                        print("Exitting Show Blinkt Attract")
                        clearBlinkt()
                        return

                    set_pixel(j, 255, 0, 0, 0.1)
                    blinkt.show()
                    time.sleep(0.05)

                for j in range(7, 0, -1):

                    if self._running == False:
                        print("Exitting Show Blinkt Attract")
                        clearBlinkt()
                        return

                    set_pixel(j, 0, 0, 0, 0.1)
                    blinkt.show()
                    time.sleep(0.05)

            except KeyboardInterrupt:
                clearBlinkt()
                sys.exit(-1)
                break
Beispiel #23
0
    def _do_cough_lights(self):
        for i in xrange(0, len(self._cough_volumes),
                        self.ms_stride_for_volume_samples):
            val = self._cough_volumes[i]
            # if val > 0.8: # just for drama
            #     val = 1.0

            if val < 0.2:
                val = 0.2

            h, s, v = self.color_hsv
            s = s - (s * val * self.whiteness_factor)  # toward white

            for led_idx in range(8):
                distance_from_center = abs(round(led_idx - 3.5))
                pct_dfc = distance_from_center / 6.0

                Helpers.set_pixel_hsv(led_idx, (h, s, v), (1.0 - pct_dfc) *
                                      val * self.max_brightness_clamp)

            blinkt.show()
            sleep(self.ms_stride_for_volume_samples / 1000.0)

        blinkt.clear()
        blinkt.show()
def make_light(start_time, filename):  # getting time.ctime()
    beginnAt = time.mktime(time.strptime(start_time))
    time.sleep(max(0, beginnAt-time.time()))

    # set_clear_on_exit()
    datalist = []
    with open(filename) as json_file:
        data = json.load(json_file)
        for frame in data:
            # json structure: list of dict(keyframeX,KeyframeY,r,g,b)
            val = [frame["r"], frame["g"], frame["b"], frame["y"]]
            datalist.append(val)

    period = 0.04
    t = time.time()
    for frame in datalist:
        t += period
        # print(frame["y"])

        # for px in range(8):
        #    set_pixel(px, val,val, val)
        #    show()
        ###set_all(r,g, b, brightness)
        set_all(frame[0], frame[1], frame[2], frame[3])
        #set_all(frame, frame, frame)
        show()

        time.sleep(max(0, t-time.time()))

    clear()
    show()
Beispiel #25
0
def on_message(client, userdata, msg):

    data = msg.payload.split(',')
    command = data.pop(0)

    if command == "clr" and len(data) == 0:
        blinkt.clear()
        blinkt.show()
        return

    if command == "bri" and len(data) == 1:
        try:
            bri = float(data[0])
        except ValueError:
            print("Malformed command: ", str(msg.payload))
            return
        blinkt.set_brightness(bri)
        blinkt.show()
        return

    if command == "rgb" and len(data) == 4:
        try:
            pixel = data.pop(0)

            if pixel == "*":
                pixel = None
            else:
                pixel = int(pixel)
                if pixel > 7:
                    print("Pixel out of range: " + str(pixel))
                    return

            r, g, b = [int(x) & 0xff for x in data]
            if args.green_hack:
                # Green is about twice the luminosity for a given value
                # than red or blue, so apply a hackish linear compensation
                # here taking care of corner cases at 0 and 255.  To do it
                # properly, it should really be a curve but this approximation
                # is quite a lot better than nothing.
                if r not in [0, 255]:
                    r = r + 1
                if g not in [0]:
                    g = g / 2 + 1
                if b not in [0, 255]:
                    b = b + 1

            print(command, pixel, r, g, b)

        except ValueError:
            print("Malformed command: " + str(msg.payload))
            return

        if pixel is None:
            for x in range(blinkt.NUM_PIXELS):
                blinkt.set_pixel(x, r, g, b)
        else:
            blinkt.set_pixel(pixel, r, g, b)

        blinkt.show()
        return
def make_light(start_time, filename):  # getting time.ctime()
    beginnAt = time.mktime(time.strptime(start_time))
    time.sleep(max(0, beginnAt - time.time()))

    # set_clear_on_exit()
    datalist = []
    with open(filename) as json_file:
        data = json.load(json_file)
        for frame in data:
            val = frame["y"] * 255
            datalist.append(val)

    period = 0.04
    t = time.time()
    for frame in datalist:
        t += period
        # print(frame["y"])

        # for px in range(8):
        #    set_pixel(px, val,val, val)
        #    show()
        set_all(frame, frame, frame)
        show()

        time.sleep(max(0, t - time.time()))

    clear()
    show()
Beispiel #27
0
def display_both_open():
    clear()
    set_pixel(1, 0, 255, 0)
    set_pixel(2, 0, 255, 0)
    set_pixel(5, 0, 255, 0)
    set_pixel(6, 0, 255, 0)
    show()
def eyes_forward(seconds, r, g, b):
    blinkt.clear()
    blinkt.set_pixel(1, r, g, b)
    blinkt.set_pixel(6, r, g, b)
    sleep(seconds)
    blinkt.clear()
    sleep(0.2)
Beispiel #29
0
def side_to_side_motion(blink_number, sleep_time, pixel_number=4):
    """ will rotate light in side to side motion """
    # set direction
    direction = 1

    # loop
    for i in range(blink_number):
        # set the pixel
        if pixel_number == 7 or pixel_number == 0:
            direction = direction * -1
        pixel_number = pixel_number + direction

        # set the colors
        red = i * 10
        blue = 255 - red
        green = 0

        # clear the old pixel
        clear()

        # set the new pixel
        set_pixel(pixel_number, red, green, blue)
        show()

        # sleep
        time.sleep(sleep_time)

    # clear at the end of the loop
    clear()
    show()
Beispiel #30
0
def on_message(client, userdata, msg):
    global state

    try:
        topic = msg.topic.split('/')[-1]

        if topic == "clear":
            state = [Color() for i in range(blinkt.NUM_PIXELS)]
            blinkt.clear()
            blinkt.show()
            return

        data = demjson.decode(msg.payload.decode())

        if topic == "set":
            pixelmask = data['mask']
            del data['mask']
            col = Color(**data)

            for x in range(blinkt.NUM_PIXELS):
                if pixelmask & (1 << x) != 0:
                    state[x] = col

    except ValueError:
        print("Malformed message: " + str(demjson.encode(msg)))
        return
    except Exception as e:
        print(e)
        return

    for x in range(blinkt.NUM_PIXELS):
        col = state[x]
        blinkt.set_pixel(x, int(col.red * 255), int(col.green * 255),
                         int(col.blue * 255))
    blinkt.show()