def FadeInOut(delay):
  for b in range(31):
    set_brightness(b/31.0)
    show()
    sleep(delay)
  for b in range(31):
    set_brightness((31-b)/31.0)
    show()
    sleep(delay)
Exemplo n.º 2
0
def splash():
   set_brightness(0.3)
   for x in range(0, 8):
       set_pixel(x, 255, 0, 0)
       show()
       time.sleep(0.1)

   time.sleep(0.1)
   for y in range(0, 8):
       set_pixel(y, 0, 0, 0)
       show()
       time.sleep(0.1)
Exemplo n.º 3
0
def main():
    blinkt.set_brightness(0.1)
    place(random_tile(max_size=4))
    update()
    
    while True:
        time.sleep(0.5)
        
        if has_lines():
            blink_lines()
            remove_lines()
            place(random_tile(max_size=4))
        else:
            gravity()
        
        update()
Exemplo n.º 4
0
def BlinktManager():
  #time.sleep(20)
  localBrightness=globalBrightness
  while not globalShutdown:  
    spacing = 360.0 / 16.0
    hue = 0
    if localBrightness!=globalBrightness:
      blinkt.set_brightness(globalBrightness)
      localBrightness=globalBrightness
    if globalResponse=='pulse':
      for z in list(range(1, 10)[::-1]) + list(range(1, 10)):
        fwhm = 5.0/z
        gauss = make_gaussian(fwhm)
        start = time.time()
        y = 4
        for x in range(blinkt.NUM_PIXELS):
          h = 0.5
          s = 1.0
          v = gauss[x, y]
          rgb = colorsys.hsv_to_rgb(h, s, v)
          r, g, b = [int(255.0 * i) for i in rgb]
          blinkt.set_pixel(x, r, g, b)
	blinkt.show()
        end = time.time()
        t = end - start
        if t < 0.04:
          time.sleep(0.04 - t)
	time.sleep(0.15)
    elif globalResponse=='rainbow':
      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)
      blinkt.show()
      time.sleep(0.15)
    elif globalResponse=='solid':
      blinkt.set_all(255, 255, 255)
      print "solid"
      time.sleep(3)
    elif globalResponse=='off':
      blinkt.set_all(0, 0, 0)
      time.sleep(3)
    blinkt.show()
def main(brightness, update_interval, blink_rate=0.1):
    tfl_status_obj = tubestatus.Status()
    should_blink = True

    while True:
        update_line_statuses(tfl_status_obj)

        # update LEDS
        for x in range(0, int(update_interval/blink_rate), 1):
            set_brightness(brightness)
            for line, line_desc in CONFIG.iteritems():
                if line_desc["open"]:
                    if line_desc["status"] != GOOD_SERVICE:
                        set_led_status(line_desc, should_blink)
                    else:
                        set_led_status(line_desc, True)

            show()
            sleep(blink_rate)
            should_blink = not should_blink
Exemplo n.º 6
0
####
# Copyright (c) 2017 Chris J Daly (github user cjdaly)
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#   cjdaly - initial API and implementation
####

import time
from blinkt import set_pixel, set_brightness, show, clear

set_brightness(0.3)
clear()
set_pixel(0, 0, 0, 100)
set_pixel(1, 0, 100, 0)
set_pixel(2, 100, 0, 0)
set_pixel(3, 0, 100, 100)
set_pixel(4, 100, 100, 0)
set_pixel(5, 100, 0, 100)
set_pixel(6, 100, 100, 100)
set_pixel(7, 10, 10, 10)
show()

while True:
    time.sleep(1.0)
Exemplo n.º 7
0
from blinkt import set_pixel, set_brightness, show, clear, time

clear()
set_brightness(0)
show()
Exemplo n.º 8
0
from blinkt import set_pixel, set_all, set_brightness, show, clear
import time
import random

set_brightness(0.2)
#set_brightness(1)

custom_brigthness = 1
sleep_time = 0.6

while True:
    pixel = random.randint(0, 7)
    pixel2 = random.randint(0, 7)
    pixel3 = random.randint(0, 7)
    color1 = random.randint(0, 15)
    color2 = random.randint(0, 15)
    #	color3 = random.randint(0, 150)

    # Set one of the colors to zero to produce less grey tones
    color3 = 0

    set_pixel(pixel, color1, color2, color3)
    set_pixel(pixel2, color2, color3, color1)
    set_pixel(pixel3, color3, color1, color2)
    show()
    time.sleep(sleep_time)

#	set_all(color1, color2, color3, custom_brigthness)
#       show()
#       time.sleep(sleep_time)
Exemplo n.º 9
0
def main():
    draw = drawer.Drawer()
    drawer.penInvert()
    draw.penUp()
    draw.toPosition(0, 0)
    set_brightness(.05)
    blinked.switchColor('g', [0])
    try:
        kinect = kinecter.kinect()
        blinked.switchColor('o', [1])
        kinect.start()
        kinect.backGroundSubstractor(nFrames=100)
        kinect.stop()
        blinked.switchColor('p', [1])
        time.sleep(20)
        kinect.start()
        kinect.getDepthFrames(nFrames=40, delay=.01, maxDepth=2049)
        kinect.stop()
        blinked.switchColor('c', [1])
        kinect.backgroundSubstract(blur=True, level=15)
        dX, dY, angle, angleZ = kinect.derivateFrames()
    except Exception as e:
        print(traceback.format_exc())

    blinked.switchColor('g', [5, 6])
    draw = drawer.DrawerNet()
    draw.penUp()
    draw.squareCorner(0, 0, widthPaper, heightPaper)
    blinked.switchColor('g', [5, 6, 7])
    nLines = 400
    size = 0

    X2 = []
    nx0 = np.int(len(kinect.frames) / 2)
    scale, nx, dist, offsetX, offsetY = spacer(kinect.frames, nx0 - 1, nx0)
    print("scale : " + str(scale))
    print("n     : " + str(nx))
    print("offsetX  : " + str(offsetX))
    print("offsetY : " + str(offsetY))
    print("dist : " + str(dist))
    xu, yu = scaler(1, 1, scale=scale, offsetX=0, offsetY=0)
    offsetA = [[-np.pi / 3, 0, np.pi / 3],
               [-2 * np.pi / 3, np.pi, 2 * np.pi / 3]]
    blinked.switchColor('a', [0])
    blinked.switchColor('g', [1])

    offsetX0 = 5 - offsetY
    offsetY0 = 5 - offsetX

    d = np.linspace(.1, 4, nx)
    nL = np.linspace(250, 600, nx)

    sp = np.linspace(.2, 1.0, nx)
    crop = np.linspace(0, .6, nx)

    try:
        for j in range(0, nx):

            blinked.progressColor(j / nx, 'v', 'y', [4])

            kFrames = j + nx0
            #dist = random.uniform((j-nx*math.floor(j/nx)),1+(j-nx*math.floor(j/nx)))*5
            #

            offsetX = offsetX0
            offsetY = offsetY0 + j * dist

            #print("offset : "+str((offsetX,offsetY)))
            X2 = drawing(kFrames,kinect.frames,angle,angleZ,draw,nLines = 300,scale = scale,A0=0,\
                    offsetX = offsetX,offsetY=offsetY,figurePosition = X2,distanceLine = .2  ,speed = .2,cropFactor=crop[j])

    except Exception as e:
        print(traceback.format_exc())
        draw.toPosition(0, 0)
    draw.closeDrawer()
    switchColor(1)
import colorsys
import time

from blinkt import set_clear_on_exit, set_brightness, set_pixel, show

import signal
import sys

# This catches the SIGINT signal which is sent by kill and cleans up the Blinkt!. In theory anyway!
def signal_handler(signal, frame):
    blinkt.clear()
    blinkt.show()
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

spacing = 360.0 / 16.0
hue = 0

set_clear_on_exit()
set_brightness(0.1)

while True:
    hue = int(time.time() * 100) % 360
    for x in range(8):
        offset = x * spacing
h        h = ((hue + offset) % 360) / 360.0
        r, g, b = [int(c*255) for c in colorsys.hsv_to_rgb(h, 1.0, 1.0)]
        set_pixel(x,r,g,b)
    show()
    time.sleep(0.001)
Exemplo n.º 11
0
from blinkt import set_pixel, set_brightness, show, clear
import time

clear()
set_brightness(0.033)
set_pixel(0, 255, 255, 255)
show()

time.sleep(1)

Exemplo n.º 12
0
####
# Copyright (c) 2017 Chris J Daly (github user cjdaly)
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#   cjdaly - initial API and implementation
####

import random
import time
from blinkt import set_pixel, set_brightness, show, clear

set_brightness(0.4)

while True:
    r = 0
    g = random.randint(0, 40)
    b = random.randint(20, 100)
    for i in range(8):
        set_pixel(i, 80, 80, 80)
        show()
        time.sleep(0.3)
        #
        set_pixel(i, 100, 100, 200)
        show()
        time.sleep(0.3)
        #
        set_pixel(i, 80, 80, 80)
Exemplo n.º 13
0
def main():
    mouseThread = threading.Thread(target = mouseListener)
    mouseThread.daemon = True
    mouseThread.start()


    draw = drawer.Drawer(dx=450,dy=230)    
    draw.penInvert()
    draw.penUp()
    draw.toPosition(0,0)
    set_brightness(.05)
    blinked.switchColor('g',[0])
    #draw.squareCorner(0,0,heightPaper,widthPaper,polar=True,xOffset = -heightPaper/2.0,yOffset =20)
    #draw.lines([0,0,heightPaper,heightPaper],[0,widthPaper,widthPaper,0],xOffset = -heightPaper/2.0,yOffset =20,polar = True)
    while(not backgroundSub):
        time.sleep(.1)

    try:
        kinect = kinecter.kinect()
        blinked.switchColor('o',[1])
        kinect.start()
        kinect.backGroundSubstractor(nFrames=100)
        kinect.stop()
        blinked.switchColor('p',[1])
        while(not drawLoop):
            time.sleep(.1)
        for k in range(0,12):
            time.sleep(.8)
            blinked.switchColor('r',[7])
            time.sleep(.2)
            blinked.switchColor('k',[7])

        for k in range(0,10):
            time.sleep(.35)
            blinked.switchColor('o',[7])
            time.sleep(.15)
            blinked.switchColor('k',[7])
        
        for k in range(0,5):
            deltaT = .3/((k+1))
            time.sleep(.9*deltaT)
            blinked.switchColor('g',[7])
            time.sleep(.1*deltaT)
            blinked.switchColor('k',[7])
        kinect.start()
        kinect.getDepthFrames(nFrames = 40,delay=.01,maxDepth=2049)
        kinect.stop()
        blinked.switchColor('c',[1])
        kinect.backgroundSubstract(blur=True,level=15)
        dX,dY,angle,angleZ = kinect.derivateFrames()
    except Exception as e: 
        print(traceback.format_exc())
 

    blinked.switchColor('g',[5,6])

    blinked.switchColor('g',[5,6,7])
    nLines = 400
    size = 0

    X2 = []
    nx0=np.int(len(kinect.frames)/2)
    scale,nx,dist,offsetX,offsetY =  spacer(kinect.frames,nx0-1,nx0)
    print("scale : "+str(scale))
    print("n     : "+str(nx))
    print("offsetX  : "+str(offsetX))
    print("offsetY : "+str(offsetY))
    print("dist : "+str(dist))
    xu,yu = scaler(1,1,scale=scale,offsetX=0,offsetY=0)
    offsetA=[[-np.pi/3,0,np.pi/3],[-2*np.pi/3,np.pi,2*np.pi/3]]    
    blinked.switchColor('a',[0])
    blinked.switchColor('g',[1])




    offsetX0 = 5-offsetY
    offsetY0 = 5-offsetX



    d = np.linspace(.1,4,nx)
    nL = np.linspace(250,1200,nx)

    sp = np.linspace(.2,1.0,nx)
    crop = np.linspace(0,.6,nx)
    speedRange = np.linspace(1,10,nx)

    try:
        for j in range(0,nx):

            blinked.progressColor(j/nx,'v','y',[4])
            
            kFrames = j+nx0
            #dist = random.uniform((j-nx*math.floor(j/nx)),1+(j-nx*math.floor(j/nx)))*5
            #
            
            offsetX = offsetX0
            offsetY = offsetY0+j*dist

            #print("offset : "+str((offsetX,offsetY)))
            X2 = drawing(kFrames,kinect.frames,angle,angleZ,draw,nLines = 200,scale = scale,A0=0,\
                    offsetX = offsetX,offsetY=offsetY,figurePosition = X2,distanceLine = .1  ,speed = .1 ,cropFactor=0,resolution=.05)
            

    except Exception as e: 
        print(traceback.format_exc())
        draw.toPosition(0,0)
    draw.closeDrawer()    
    switchColor(1)
 def __init__(self):
     for i in range(8):
         self.leds.append(Led())
     set_brightness(0.1)
Exemplo n.º 15
0
####
# Copyright (c) 2017 Chris J Daly (github user cjdaly)
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#   cjdaly - initial API and implementation
####

import random
import time
from blinkt import set_pixel, set_brightness, show, clear

set_brightness(0.4)

while True:
  r = 0
  g = random.randint(0,40)
  b = random.randint(20,100)
  for i in range(8):
    set_pixel(i,80,80,80)
    show()
    time.sleep(0.3)
    #
    set_pixel(i,100,100,200)
    show()
    time.sleep(0.3)
    #
    set_pixel(i,80,80,80)
Exemplo n.º 16
0
 def setBrightness(self, percent):
     brightness = self.validateBrightness(percent)
     blinkt.set_brightness(brightness)
     blinkt.show()
Exemplo n.º 17
0
 def on(self, col):
     set_brightness(self.brightness)
     for i in range(8):
         set_pixel(i, colors(col)[0], colors(col)[1], colors(col)[2])
     show()
Exemplo n.º 18
0
    def run(self):
        MODE_HOUR = 0
        MODE_MIN = 1
        MODE_SEC = 2

        time_to_stay_in_mode = 3
        time_in_mode = 0
        mode = 0

        lh = 0
        lm = 0

        while self.running:
            t = localtime()
            h, m, s = t.tm_hour, t.tm_min, t.tm_sec

            if h != lh:
                mode = MODE_HOUR
                time_in_mode = 0

            elif m != lm:
                mode = MODE_MIN
                time_in_mode = 0

            lm = m
            lh = h

            blinkt.clear()

            if (s % 2) == 0:
                blinkt.set_pixel(1, 64, 64, 64)

            if mode == MODE_HOUR:
                blinkt.set_pixel(0, 255, 0, 0)
                for x in range(6):
                    bit = (h & (1 << x)) > 0
                    r, g, b = [128 * bit] * 3
                    blinkt.set_pixel(7 - x, r, g, b)

            if mode == MODE_MIN:
                blinkt.set_pixel(0, 0, 255, 0)
                for x in range(6):
                    bit = (m & (1 << x)) > 0
                    r, g, b = [128 * bit] * 3
                    blinkt.set_pixel(7 - x, r, g, b)

            if mode == MODE_SEC:
                blinkt.set_pixel(0, 0, 0, 255)
                for x in range(6):
                    bit = (s & (1 << x)) > 0
                    r, g, b = [128 * bit] * 3
                    blinkt.set_pixel(7 - x, r, g, b)

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

            time_in_mode += 1
            if time_in_mode == time_to_stay_in_mode:
                mode += 1
                mode %= 3
                time_in_mode = 0

            sleep(1)
Exemplo n.º 19
0
def blinkt_init():

    blinkt.set_brightness(BRIGHTNESS)
    blinkt.clear()
    blinkt.show()
Exemplo n.º 20
0
####
# Copyright (c) 2017 Chris J Daly (github user cjdaly)
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
#   cjdaly - initial API and implementation
####

import time
from blinkt import set_pixel, set_brightness, show, clear

set_brightness(0.3)
clear()
set_pixel(0,   0,   0, 100)
set_pixel(1,   0, 100, 0)
set_pixel(2, 100,   0, 0)
set_pixel(3,   0, 100, 100)
set_pixel(4, 100, 100, 0)
set_pixel(5, 100,   0, 100)
set_pixel(6, 100, 100, 100)
set_pixel(7,  10,  10, 10)
show()

while True:
  time.sleep(1.0)

Exemplo n.º 21
0
def show_color_line(r, g, b, t):
    blinkt.set_brightness(0.5)
    for i in range(0, 8):
        blinkt.set_pixel(i, r, g, b)
        blinkt.show()
        time.sleep(t)
Exemplo n.º 22
0
import openweathermapy as owm
import time
import blinkt

blinkt.set_clear_on_exit()
blinkt.set_brightness(0.05)
settings = {"APPID": 'cf989ed49dcc85f0d4a44cb03939d3b0', "units": "metric"}

colors = {}
colors['white'] = {'r': 255, 'g': 255, 'b': 255}
colors['blue'] = {'r': 0, 'g': 0, 'b': 255}
colors['green'] = {'r': 0, 'g': 255, 'b': 0}
colors['yellow'] = {'r': 255, 'g': 230, 'b': 0}
colors['orange'] = {'r': 255, 'g': 188, 'b': 0}
colors['red'] = {'r': 255, 'g': 0, 'b': 0}

while True:

    data = owm.get_current("Amsterdam,NL", **settings)
    temp = data("main.temp")

    print temp

    if (temp < 5):
        color = 'white'
    elif (temp > 5 and temp <= 10):
        color = 'blue'
    elif (temp > 10 and temp <= 14):
        color = 'green'
    elif (temp > 14 and temp <= 18):
        color = 'yellow'
Exemplo n.º 23
0
def show_color(r, g, b):
    blinkt.set_brightness(0.5)
    for i in range(0, 8):
        blinkt.set_pixel(i, r, g, b)
    blinkt.show()
Exemplo n.º 24
0
import sys
import tty
import termios
import numpy
import threading
import random, time
import colorsys

import blinkt as uh

GLOBAL_BRIGHTNESS = .05
uh.set_brightness(GLOBAL_BRIGHTNESS)

#Input defintions
#I found this somewhere for keyboard key usage. Maybe @gadgetoid? Thanks!
fd = ''


def readchar():
    global old_settings
    global fd
    fd = sys.stdin.fileno()

    old_settings = termios.tcgetattr(fd)
    try:
        tty.setraw(sys.stdin.fileno())
        ch = sys.stdin.read(1)
    finally:
        termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
    if ch == '0x03':
        raise KeyboardInterrupt
Exemplo n.º 25
0
#!/usr/bin/env python

import time          # so we can wait between frames
import blinkt        # so we can talk to our blinkt lights!

BRIGHTNESS = 0.2     # range is 0.0 to 1.0
MAX_COLOUR = 255     # range is 0 to 255
DECAY_FACTOR = 1.5   # how quickly should MAX_COLOUR fade? (1.5 works well)
TIME_SLEEP = 0.04    # seconds (0.04 works well)

PIXELS = blinkt.NUM_PIXELS  # usually 8, can use fewer if you like!

blinkt.clear         # make all pixels blank / black
blinkt.set_brightness(BRIGHTNESS)

brightpixel = -1
direction = 1

print('Hello Michael.\nHow are you today?')

while True:
    # decay all pixels
    for x in range(PIXELS):
        pixel = blinkt.get_pixel(x)  # format is [ r, g, b, brightness? ]
        blinkt.set_pixel(x, pixel[0] / DECAY_FACTOR, 0, 0)

    # brightpixel should move back and forth all the pixels,
    # in a ping-pong, triangle wave. Not (co)sine.
    brightpixel += direction

    if brightpixel >= PIXELS - 1:
Exemplo n.º 26
0
def main():
    set_brightness(.05)
    blinked.switchColor('g', [0])
    try:
        kinect = kinecter.kinect()
        blinked.switchColor('o', [1])
        kinect.start()
        kinect.backGroundSubstractor(nFrames=100)
        kinect.stop()
        blinked.switchColor('p', [1])
        time.sleep(10)
        kinect.start()
        kinect.getDepthFrames(nFrames=40, delay=.01, maxDepth=2049)
        kinect.stop()
        blinked.switchColor('c', [1])
        kinect.backgroundSubstract(blur=True, level=20)
        dX, dY, angle, angleZ = kinect.derivateFrames()
    except Exception as e:
        print(traceback.format_exc())
        noProblem = False

    draw = drawer.Drawer(output=False)
    switchColor(2)
    print('---Switch is strating')
    #intializeDrawer()
    flip = False

    z = kinect.frames[6]
    A = angle[6]
    idx = [6, 7, 8]
    nLines = 200
    size = 0
    X = []
    X2 = []
    scale = 70
    xu, yu = scaler(1, 1, scale=scale, offsetX=0, offsetY=0)
    offsetA = [[-np.pi / 3, 0, np.pi / 3],
               [-2 * np.pi / 3, np.pi, 2 * np.pi / 3]]
    blinked.switchColor('a', [0])
    blinked.switchColor('g', [1])
    rounder = .5
    speed = 2 * rounder

    rounder2 = 3 * rounder
    if speed < rounder:
        speed = rounder

    try:
        for j in range(0, 64):
            X3 = []
            blinked.progressColor(j / 10, 'v', 'y', [4])
            nLines = 200  #75*(3*l+j+1)
            kFrames = random.randint(0, len(angle) - 1)
            z = kinect.frames[kFrames]
            A = angle[kFrames]
            dist = random.uniform((j - 8 * math.floor(j / 8)), 1 +
                                  (j - 8 * math.floor(j / 8))) * 25
            offsetX = 5 + math.floor(j / 8) * 10
            offsetY = 5 + dist
            print('offset : ' + str((offsetX, offsetY)))
            #offsetY = 5+j*27
            #offsetX = 5
            rounder = .5
            speed = 2 * rounder

            rounder2 = 3 * rounder
            if speed < rounder:
                speed = rounder
            for k in range(0, nLines):
                blinked.progressColor(k / nLines, 'v', 'y', [5])
                size = 0
                while (size == 0):
                    xLines = []
                    yLines = []

                    size = 0
                    xChecking = True
                    while xChecking:
                        kx = random.randint(0, 639)
                        ky = random.randint(0, 479)
                        x, y = scaler(kx,
                                      ky,
                                      scale=scale,
                                      offsetX=offsetX,
                                      offsetY=offsetY)
                        x = round(x + (.5 - random.random()) * xu,
                                  rounder / 2.0)
                        y = round(y + (.5 - random.random()) * yu,
                                  rounder / 2.0)
                        x2 = round(x, rounder2)
                        y2 = round(y, rounder2)
                        zTest = z[ky, kx]
                        Atest = A[ky, kx]
                        if (x2, y2) not in X2:
                            xChecking = False
                    running = True
                    if np.isnan(zTest) or np.isnan(Atest):
                        running = False
                    while running:
                        #print('x  : '+str((x,y)))
                        #print('k  : '+str((kx,ky)))
                        xLines.append(y)
                        yLines.append(x)
                        X.append((x, y))
                        X3.append((x2, y2))
                        dx = round(x + speed * np.cos(A[ky, kx]), rounder)
                        dy = round(y + speed * np.sin(A[ky, kx]), rounder)
                        dx2 = round(x + speed * np.cos(A[ky, kx]), rounder2)
                        dy2 = round(y + speed * np.sin(A[ky, kx]), rounder2)

                        dxk, dyk = scaler(dx,
                                          dy,
                                          scale=scale,
                                          offsetX=offsetX,
                                          offsetY=offsetY,
                                          invert=True)

                        if (dxk > -1) and (dxk < 640) and (dyk > -1) and (
                                dyk < 480) and size < 100 and (
                                    dx, dy) not in X and (dx2, dy2) not in X2:
                            x = dx
                            y = dy
                            kx = dxk
                            ky = dyk
                            zTest = z[ky, kx]
                            Atest = A[ky, kx]
                            size += speed
                            if np.isnan(zTest) or np.isnan(Atest):
                                running = False
                        else:
                            running = False

                print('new Line : ' + str(k))
                draw.lines(xLines, yLines)
            for x3 in X3:
                if x3 not in X2:
                    X2.append(x3)
        #line(50,50,length=50,angle=0)
        #line(50,50,length=55,angle=.1)
        #line(50,50,length=60,angle=.2)
        #line(50,50,length=65,angle=.4)
        #line(50,50,length=70,angle=.8)
        #line(50,50,length=75,angle=1.6)
        #for k in range(0,10):
        #draw.square(100,70,10*k/2.0,noise = 3,speed=500)
        #for j in range(0,10):
        #square((k+1)*11,(j+1)*11,10,angle=math.pi*(k*j)/(400))
        #draw.circle((k+1)*11,(j+1)*11,k+j)
    except Exception as e:
        print(traceback.format_exc())
        draw.toPosition(0, 0)
    draw.closeDrawer()
    switchColor(1)
Exemplo n.º 27
0
parser.add_argument('--initial_hue', default=0, type=float, help='Initial hue')
parser.add_argument('--speed', default=SPEED, type=float, help='Animation speed')
parser.add_argument('--brightness', default=BRIGHTNESS, type=float, help='LED Brightness')
args = parser.parse_args()

# Init hsl colors in hls, hue, saturation, lightness
hsl = [(0.0, 0.0, 0.0)] * NUM_LEDS

# Init animation variables
dir = 1
pos = 0
hue = float(args.initial_hue)

# Init blinkt
blinkt.set_clear_on_exit(True)
blinkt.set_brightness(args.brightness)

# Forever loop
while True:
    # Apply dimming to all LEDs
    for i in range(NUM_LEDS):
        h, s, l = hsl[i]
        hsl[i] = (h, s * args.dim_factor, l)

    # Set the current LED to full brightness
    hsl[pos] = (hue, 0.5, 1.0)
    
    # Set LEDs
    blinkt.clear()
    for i in range(8):
        h, s, l = hsl[i]
Exemplo n.º 28
0
from blinkt import set_pixel, set_brightness, show, clear
import time

set_brightness(0.05)

clear()
set_pixel(0, 255, 255, 255)
show()

time.sleep(1.0)
clear()
show()

time.sleep(0.25)
clear()
set_pixel(0, 255, 0, 0)
set_pixel(1, 255, 255, 0)
set_pixel(2, 0, 255, 0)
show()

time.sleep(1.0)
clear()
show()

time.sleep(0.25)
clear()
set_pixel(0, 255, 0, 0)
set_pixel(1, 255, 255, 0)
set_pixel(2, 0, 255, 0)
show()
Exemplo n.º 29
0
import os, signal
from blinkt import clear, set_brightness, set_pixel, show, set_all
from time import sleep

hostlist = [
    "192.168.1.1", "192.168.1.2", "192.168.1.3", "192.168.1.4", "192.168.1.5",
    "192.168.1.6", "192.168.1.7", "8.8.8.8"
]
hostid = [
    "Device1", "Device2", "Device3", "Device4", "Device5", "Device6",
    "Device7", "Device8"
]

clear()
set_brightness(0.50)
set_all(0, 0, 255)
show()
sleep(5)


def handler(signum, frame):
    clear()
    show()
    exit(0)


signal.signal(signal.SIGTERM, handler)

while True:
    for hostnum, hostname in enumerate(hostlist):
        response = os.system("ping -c 1 -w2 " + hostname + " > /dev/null 2>&1")
Exemplo n.º 30
0
from werkzeug.middleware.proxy_fix import ProxyFix
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)

# APSCHEDULER #
scheduler = APScheduler()
scheduler.api_enabled = True
scheduler.init_app(app)
scheduler.start()

# NGROK #
ngrok.set_auth_token(app_config.NGROK_SECRET)
http_tunnel = ngrok.connect('https://localhost:5000/', bind_tls=True)

# BLINKT #
blinkt.set_clear_on_exit(True)
blinkt.set_brightness(0.2)
blinkt.show()



######################
## Hardware Control ##
######################

def Available():
    blinkt.set_all(0, 255, 0)
    blinkt.show()

def Busy():
    blinkt.set_all(255, 220, 0)
    blinkt.show()
Exemplo n.º 31
0
def main():
    set_brightness(.05)
    switchColor(1)
    try:
        frames = kinecter.getFrames(7)
        dX, dY, angle, angleZ = kinecter.derivateFrames(frames)
        noProblem = True
    except Exception as e:
        print(traceback.format_exc())
        noProblem = False

    draw = drawer.Drawer(output=False)
    switchColor(2)
    print('---Switch is strating')
    #intializeDrawer()
    flip = False

    speed = 1
    z = frames[6]
    A = angle[6]
    idx = [6, 7, 8]
    nLines = 200
    size = 0
    X = []
    scale = 70
    xu, yu = scaler(1, 1, scale=scale, offsetX=0, offsetY=0)
    offsetA = [[2 * np.pi / 3, 0, np.pi / 3], [2 * np.pi / 3, 0, np.pi / 3]]
    try:
        for j in range(0, 3):
            for l in range(0, 2):
                #z = frames[j]
                #A = angle[j]
                offsetX = 5 + j * 80
                offsetY = 5 + l * 80
                nLines = 75 * (3 * l + j + 1)

                xLines, yLines = kinecter.drawGradient(z,
                                                       A,
                                                       nLines=nLines,
                                                       speed=speed,
                                                       offsetX=offsetX,
                                                       offsetY=offsetY,
                                                       scale=scale)
                draw.lines(xLines, yLines)

        #line(50,50,length=50,angle=0)
        #line(50,50,length=55,angle=.1)
        #line(50,50,length=60,angle=.2)
        #line(50,50,length=65,angle=.4)
        #line(50,50,length=70,angle=.8)
        #line(50,50,length=75,angle=1.6)
        #for k in range(0,10):
        #draw.square(100,70,10*k/2.0,noise = 3,speed=500)
        #for j in range(0,10):
        #square((k+1)*11,(j+1)*11,10,angle=math.pi*(k*j)/(400))
        #draw.circle((k+1)*11,(j+1)*11,k+j)
    except Exception as e:
        print(traceback.format_exc())
        draw.toPosition(0, 0)
    draw.closeDrawer()
    switchColor(1)
Exemplo n.º 32
0
import subprocess, signal, time, sys


def signal_handler(signal, frame):
    """
    This signal handler allows us to background
    the process and send it a simple SIGINT to tell it to
    exit cleanly.
    """
    sys.exit(0)


#Start the signal handler for SIGINT
signal.signal(signal.SIGINT, signal_handler)

set_brightness(0.5)

x = 0
while x < 50:

    subprocess.call("/home/pi/Pimoroni/blinkt/examples/wget.sh", shell=True)

    time.sleep(0.5)

    print "calling file"
    num_lines = sum(1 for line in open('/mnt/ramdisk/down.htm'))
    num_linespart = sum(1 for line in open('/mnt/ramdisk/part.htm'))
    print "lines counted"

    print num_lines
    print num_linespart
Exemplo n.º 33
0
"""
Makes rainbows using blinkt
"""
import colorsys
import time
import datetime

from blinkt import set_brightness, set_pixel, show

spacing = 360.0 / 16.0
hue = 0

set_brightness(0.04)

while datetime.datetime.now().minute == 0:
    hue = int(time.time() * 100) % 360
    for x in range(8):
        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)]
        set_pixel(x, r, g, b)
    show()
    time.sleep(0.001)
Exemplo n.º 34
0
import time

import blinkt


blinkt.set_clear_on_exit()

def show_graph(v, r, g, b):
    v *= blinkt.NUM_PIXELS
    for x in range(blinkt.NUM_PIXELS):
        if v < 0:
            r, g, b = 0, 0, 0
        else:
            r, g, b = [int(min(v,1.0) * c) for c in [r, g, b]]
        blinkt.set_pixel(x, r, g, b)
        v -= 1

    blinkt.show()

blinkt.set_brightness(0.1)

try:
    while True:
        t = time.time()
        v = (math.sin(t) + 1) / 2 # Get a value between 0 and 1
        show_graph(v, 255, 0, 255)
        time.sleep(0.01)

except KeyboardInterrupt:
    pass
Exemplo n.º 35
0
 def __init__(self):
     self._display = Display.OFF
     set_brightness(0.1)
     clear()
Exemplo n.º 36
0
import blinkt

blinkt.set_clear_on_exit()


def show_graph(v, r, g, b):
    v *= blinkt.NUM_PIXELS
    for x in range(blinkt.NUM_PIXELS):
        if v < 0:
            r, g, b = 0, 0, 0
        else:
            r, g, b = [int(min(v, 1.0) * c) for c in [r, g, b]]
        blinkt.set_pixel(x, r, g, b)
        v -= 1

    blinkt.show()


blinkt.set_brightness(1 / 31.0)  #lowest brightness

while True:
    try:
        with open('/var/tmp/value.txt') as f:
            v = float(f.read()) / 100
    except:
        # v = psutil.cpu_percent() / 100.0
        v = 0.5

    show_graph(v, 255, 255, 255)
    time.sleep(0.5)
Exemplo n.º 37
0
#!/usr/bin/env python

from time import localtime, sleep

from blinkt import set_clear_on_exit, set_pixel, set_brightness, clear, show


print("Hour = Red, Minute = Green, Second = Blue")

set_clear_on_exit()

set_brightness(0.2)

on_value = 64

while True:
    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))

    clear()

    # Blink LED 0
    c = on_value * (s % 2)
    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
Exemplo n.º 38
0
def init():
    set_brightness(0.1)
Exemplo n.º 39
0
 def __init__(self, loop):
     self.loop = loop
     set_brightness(0.1)
     set_clear_on_exit()
Exemplo n.º 40
0
def process_event(event, device_id):
    """Pretty prints events.
    Prints all events that occur with two spaces between each new
    conversation and a single space between turns of a conversation.
    Args:
        event(event.Event): The current event to process.
    """
    if event.type == EventType.ON_CONVERSATION_TURN_STARTED:
        subprocess.Popen(["aplay", "/home/pi/GassistPi/sample-audio-files/Fb.wav"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        #Uncomment the following after starting the Kodi
        #status=mutevolstatus()
        #vollevel=status[1]
        #with open('/home/pi/.volume.json', 'w') as f:
               #json.dump(vollevel, f)
        #kodi.Application.SetVolume({"volume": 0})
        GPIO.output(5,GPIO.HIGH)
        led.ChangeDutyCycle(100)
        print()
    print(event)

    if (event.type == EventType.ON_RESPONDING_STARTED and event.args and not event.args['is_error_response']):
       GPIO.output(5,GPIO.LOW)
       GPIO.output(6,GPIO.HIGH)
       led.ChangeDutyCycle(50)

    if event.type == EventType.ON_RESPONDING_FINISHED:
       GPIO.output(6,GPIO.LOW)
       GPIO.output(5,GPIO.HIGH)
       led.ChangeDutyCycle(100)

    print(event)

    if (event.type == EventType.ON_CONVERSATION_TURN_FINISHED and
            event.args and not event.args['with_follow_on_turn']):
        GPIO.output(5,GPIO.LOW)
        led.ChangeDutyCycle(0)
        #Uncomment the following after starting the Kodi
        #with open('/home/pi/.volume.json', 'r') as f:
               #vollevel = json.load(f)
               #kodi.Application.SetVolume({"volume": vollevel})
        print()

    if event.type == EventType.ON_DEVICE_ACTION:
        for command, params in process_device_actions(event, device_id):
            print('Do command', command, 'with params', str(params))
            if command=='action.devices.commands.OnOff':
                if params['on']:
                    blinkt.set_all(255, 255, 255,brightness=0.05)
                    blinkt.show()
                else:
                    blinkt.clear()
                    blinkt.show()
            if command=='action.devices.commands.ColorAbsolute':
                r,g,b=colourconv(params['color']['spectrumRGB'])
                print(r,g,b)
                blinkt.set_all(r,g,b)
                blinkt.show()
            if command=='action.devices.commands.BrightnessAbsolute':
                bright=(params['brightness'])/100
                blinkt.set_brightness(bright)
                blinkt.show()
# blinkt_pattern.py
# produce pulsing light sequence read from a file.
# an improvement on cylon.py

# import modules
import blinkt, sys, os
from time import sleep

# set brightness
blinkt.set_brightness(0.1)


# read in file
filename = sys.argv[1]+".csv"
if os.path.isfile(filename):
    # file exists, read file and create pattern list
    fh = open(filename, "r")
    records = fh.readlines()
    pattern = []
    for record in records:
        record = record.strip()
        a, b, c, d, e, f, g, h = record.split(',')
        pattern.append([a, b, c, d, e, f, g, h])
else:
    print("Sorry, " + filename + " not found!")
    exit()
        
# main loop - run indefinitely
try:
    while True:
        for lines in pattern:
Exemplo n.º 42
0
import time

from blinkt import set_clear_on_exit, set_pixel, show, set_brightness


set_clear_on_exit()
set_brightness(0.1)

while True:
    for i in range(8):
        if i == 0 or i == 1:
            set_pixel(i, 255, 0, 0)
        else:
            set_pixel(i, 255, 0, 0)
            set_pixel(i-2, 0, 0, 0)
        show()
        time.sleep(0.1)
        if i == 7:
            set_pixel(i-1, 0, 0, 0)
            show()
            time.sleep(0.1)
            set_pixel(i, 0, 0, 0)
            show()

    time.sleep(0.25)

    for i in range (7, -1, -1):
        if i == 7 or i == 6:
            set_pixel(i, 255, 0, 0)
        else:
            set_pixel(i, 255, 0, 0)
Exemplo n.º 43
0
import sys
import datetime
from blinkt import set_pixel, show, set_brightness
from picamera import PiCamera
from os import system
from time import sleep

if len(sys.argv) < 3:
    print('ERROR: missing argument')
    sys.exit(2)

camera = PiCamera()
#camera.resolution = (1024, 768)

# set global blinkt brightness low
set_brightness(0.05)

def blinkt_clear():
    for led in range(8):
        set_pixel(led,0,0,0)
    show()

while True:
    blinkt_clear()

    # prepare filename from given path and current time
    now = datetime.datetime.now()
    filename = sys.argv[2] + '/' + now.strftime("timelapse_%Y-%m-%d_%H-%M-%S.jpg")

    # take picture
    set_pixel(0,255,0,0)