示例#1
0
    def flicker(self, color, minHue, maxHue, speed):
        everloop = ['black'] * led.length

        adjustedColor = 0

        asc = True

        while self.isRunning:

            if asc and adjustedColor != maxHue:
                adjustedColor += 1
            elif asc and adjustedColor == maxHue:
                adjustedColor -= 1
                asc = not asc
            elif not asc and adjustedColor != minHue:
                adjustedColor -= 1
            elif not asc and adjustedColor == minHue:
                adjustedColor += 1
                asc = not asc

            for i in range(len(everloop)):
                everloop[i] = {color: adjustedColor}

            led.set(everloop)

            sleep(1 / speed)
def gameOver():
    everloop = ['black'] * led.length

    ledAdjust = 0.0
    if len(everloop) == 35:
        ledAdjust = 0.51 # MATRIX Creator
    else:
        ledAdjust = 1.01 # MATRIX Voice

    frequency = 0.375
    counter = 0.0
    tick = len(everloop) - 1
    
    count = 0
    while count < 70:
        # Create rainbow
        for i in range(len(everloop)):
            r = round(max(0, (sin(frequency*counter+(pi/180*240))*155+100)/10))
            g = round(max(0, (sin(frequency*counter+(pi/180*120))*155+100)/10))
            b = round(max(0, (sin(frequency*counter)*155+100)/10))

            counter += ledAdjust

            everloop[i] = {'r':r, 'g':g, 'b':b}

        # Slowly show rainbow
        if tick != 0:
            for i in reversed(range(tick)):
                everloop[i] = {}
            tick -= 1

        led.set(everloop)
        sleep(.035)
        count += 1
    def showlights(self):
        everloop = ['black'] * led.length
        ledAdjust = 1.01 # MATRIX Voice
        frequency = 0.375
        counter = 0.0
        tick = len(everloop) - 1
        for m in range(0,36):
            # Create rainbow
            for i in range(len(everloop)):
                r = round(max(0, (sin(frequency*counter+(pi/180*240))*155+100)/10))
                g = round(max(0, (sin(frequency*counter+(pi/180*120))*155+100)/10))
                b = round(max(0, (sin(frequency*counter)*155+100)/10))

                counter += ledAdjust

                everloop[i] = {'r':r, 'g':g, 'b':b}

            # Slowly show rainbow
            if tick != 0:
                for i in reversed(range(tick)):
                    everloop[i] = {}
                tick -= 1

            led.set(everloop)

            sleep(.035)
        everloop = ['black'] * led.length
        led.set(everloop)
示例#4
0
def fallDetected():
    phoneContact()
    while True:
        led.set('Red')
        time.sleep(.5)
        led.set('Black')
        time.sleep(.5)
示例#5
0
    def applyRainbow(self, ledarray, times):
        print("Applying rainbow")
        
        everloop = ['black'] * led.length

        ledAdjust = 0.51 # MATRIX Creator

        frequency = 0.375
        counter = 0.0
        tick = len(everloop) - 1

        for j in range(int(times[0]) * len(everloop)):
        # Create rainbow
            for i in range(len(everloop)):
                r = round(max(0, (sin(frequency*counter+(pi/180*240))*155+100)/10))
                g = round(max(0, (sin(frequency*counter+(pi/180*120))*155+100)/10))
                b = round(max(0, (sin(frequency*counter)*155+100)/10))

                counter += ledAdjust

                everloop[i] = {'r': r, 'g': g, 'b': b}

            # Slowly show rainbow
            if tick != 0:
                for i in reversed(range(tick)):
                    everloop[i] = {}
                tick -= 1

            led.set(everloop)

            time.sleep(.035)

        self.applyClear(ledarray,1)
示例#6
0
def nextTurn():
    everloop = ['black'] * led.length
    everloop[0] = {'b': 100}
    for x in range(led.length):
        everloop.append(everloop.pop(0))
        led.set(everloop)
        time.sleep(0.1)
示例#7
0
def simon(simonList):
    # For every color simon has in the list turn on the led that color
    for color in simonList:
        led.set(color)
        time.sleep(0.30)
        # Turn it off for a bit
        led.set('black')
        time.sleep(0.25)
示例#8
0
def on_message(ws, message):
    data = json.loads(message)
    print("**Captured New Intent**")
    print(data)

    if ("Led" == data["intent"]["name"]):
        led.set(data["slots"]["color"])
        say("Device changed to: " + data["slots"]["color"])
 def handle_detect_error(self, message):
     try:
         led.set('red')
         time.sleep(5)
         led.set()
     except:
         LOGGER.error("Impossible to set light to red")
         pass
示例#10
0
 def applyRoundinaCircle(self, ledarray, args):
     everloop = ['black'] * led.length
     everloop[0] = 'blue' #args[0]
     for i in range(int(args[0]) * led.length):
         everloop.append(everloop.pop(0))
         led.set(everloop)
         time.sleep(0.050)
     self.applyClear(ledarray,1)
示例#11
0
 def applyProxArray(self, array):  # array is an array of integers
     ratio = len(array) / len(self.ledarray)
     for i in range(0, len(self.ledarray)):
         low = round(i * ratio)
         high = round((i + 1) * ratio)
         if high > len(array):
             high = len(array)
         intensity = round(stat.mean(array[low:high]) / self.MAXDISTANCE * 255)
         self.ledarray[i] = {'r': intensity, 'g': 0, 'b': 0, 'w': 0}  # red
     led.set(self.ledarray)
def fade_out(max_color):
	led.set('black')
	min_color = [0,0,0,0]
	terminate = [0,0,0,0]
	terminate = [0,0,0,0]
	while terminate != [1,1,1,1]:
		for n in range(4):
			if color[n] > min_color[n]:
				color[n] -= (max_color[n]/255)
			else:
				terminate[n] = 1
		led.set((color[0],color[1],color[2],color[3]))
		print(color)
		time.sleep(.002)
示例#13
0
def verifySimon(color, counter):
    if color == '2869x255':
        color = 'red'
    elif color == '44161x255':
        color = 'blue'
    elif color == '11222x255':
        color = 'yellow'
    elif color == '21845x255':
        color = 'green'
    led.set(color)
    if (simonList[counter] == color):
        return True
    else:
        print('game over')
        gameover()
        return False
def fade_in(max_color):
	led.set('black')
	color = [0,0,0,0]
	min_color = [0,0,0,0]
	terminate = [0,0,0,0]
	delay = 0.0015

	while terminate != [1,1,1,1]:
		for n in range(4):
			if color[n] < max_color[n]:
				color[n] += (max_color[n]/255)
			else:
				terminate[n] = 1
		led.set((color[0],color[1],color[2],color[3]))
		print(color)
		time.sleep(delay)
	return array_gen(color)
示例#15
0
    def _led_rainbow(self):
        try:
            sleep(3)
            # Turn on the rainbow for 15 seconds
            t_end = time() + 15

            everloop = ['black'] * led.length

            ledAdjust = 0.0
            if len(everloop) == 35:
                ledAdjust = 0.51  # MATRIX Creator
            else:
                ledAdjust = 1.01  # MATRIX Voice

            frequency = 0.375
            counter = 0.0
            tick = len(everloop) - 1

            while time() < t_end:
                # Create rainbow
                for i in range(len(everloop)):
                    r = round(
                        max(0, (sin(frequency * counter +
                                    (pi / 180 * 240)) * 155 + 100) / 10))
                    g = round(
                        max(0, (sin(frequency * counter +
                                    (pi / 180 * 120)) * 155 + 100) / 10))
                    b = round(
                        max(0, (sin(frequency * counter) * 155 + 100) / 10))

                    counter += ledAdjust

                    everloop[i] = {'r': r, 'g': g, 'b': b}

                # Slowly show rainbow
                if tick != 0:
                    for i in reversed(range(tick)):
                        everloop[i] = {}
                    tick -= 1

                led.set(everloop)

                sleep(.035)
        finally:
            led.set('black')
def heatIndex():
	temperatureHI = (sensors.pressure.read().temperature) - 5
	humidityHI = sensors.humidity.read().humidity
	hi = heat_index(temperature=temperatureHI, humidity= humidityHI)

	ledSet = []

	for x in range(1, int(hi)):
		ledSet.append((25,0,25,0))
		led.set(ledSet)
		time.sleep(0.1)

	if (int(hi) >= 40):
		phoneContact()
		dangerAlert()

	print(hi)
	time.sleep(5)
def humidityReadout():
    humidity = sensors.humidity.read().humidity
    print(humidity)

    humidityLED = int((humidity / 100) * 35)

    if (humidityLED > 34):
        humidityLED = humidityLED / 2
        brightness = 2
    else:
        brightness = 1
    ledSet = []

    for x in range(1, int(humidityLED)):
        ledSet.append((0, 0, 25 * brightness, 0))
        led.set(ledSet)
        time.sleep(0.1)

    time.sleep(5)
示例#18
0
 def _alarm_off(self):
     # Alarm is no turned off
     try:
         led.set("red")
         sleep(4)
         led.set("black")
     finally:
         led.set("black")
示例#19
0
 def _alarm_on(self):
     # Alarm is no turned on
     try:
         led.set("green")
         sleep(4)
         led.set("black")
     finally:
         led.set("black")
示例#20
0
 def _led_light(self):
     try:
         sleep(3)
         led.set('white')
         sleep(5)
         led.set('white')
         sleep(180)
     finally:
         led.set('black')
示例#21
0
 def _status_update_failed(self):
     # Alarm status update failed
     try:
         for x in range(4):
             led.set("yellow")
             sleep(.5)
             led.set("black")
             sleep(.5)
     finally:
         led.set("black")
示例#22
0
def gameover():
    global simonList
    for i in range(3):
        led.set('red')
        time.sleep(0.5)
        led.set('white')
        time.sleep(0.5)
    led.set('black')
    nextTurn()
    simonList = []
def humidityReadout():
	humidity = sensors.humidity.read().humidity
	print(humidity)
	color = [0,50,255,0]

	humidityLED = int((humidity / 100) * 35)
	removeLED = 35 - humidityLED
	print('remove ' + str(removeLED))
	led_list = fade_in([0,50,255,0])
	print(led_list)
	p = 0
	n = 34

	while removeLED > 0:
		if removeLED > 0:
			led_list[p] = 'black'
			led.set(led_list)
			p += 1
			removeLED -= 1
			time.sleep(0.05)

		if removeLED > 0:
			led_list[n] = 'black'
			led.set(led_list)
			n -= 1
			removeLED -= 1
			time.sleep(0.05)

	time.sleep(4)
	removeLED = humidityLED

	while removeLED > 0:
		if removeLED > 0:
			led_list[p] = 'black'
			led.set(led_list)
			p += 1
			removeLED -= 1
			time.sleep(0.05)

		if removeLED > 0:
			led_list[n] = 'black'
			led.set(led_list)
			n -= 1
			removeLED -= 1
			time.sleep(0.05)
示例#24
0
def flashLights(color, times, intensity):
    everloop = ['black'] * led.length
    led.set(everloop)

    for i in range(0, times):
        for j in range(len(everloop)):
            everloop[j] = {color: intensity}

        led.set(everloop)
        sleep(0.2)

        everloop = ['black'] * led.length
        led.set(everloop)

        sleep(0.2)
def temperatureReadout(override):
	temperature = sensors.pressure.read().temperature
	print(temperature)

	temperatureLED = temperature - 7

	if (override > 0):
		temperatureLED = override

	ledSet = []

	for x in range(1, int(temperatureLED)):
		ledSet.append((25,0,0,0))
		led.set(ledSet)
		time.sleep(0.1)

	led.set(ledSet)

	if(temperatureLED > 28):
		phoneContact()
		led.set('White')
		dangerAlert()

	time.sleep(5)
示例#26
0
 def show(self):
     led.set(self._colors)
示例#27
0
 def clearStrip(self):
     self._colors = self._newArray()
     led.set()
示例#28
0
 def stop_displaying(self, *args, **kwargs):
     self._display_time = False
     led.set("black")
示例#29
0
 def close(self):
     self._thread_flag.set()
     led.set("black")
示例#30
0
 def _set_minute(self, minute):
     # ceil: i want to display like 10:52 as 10:55,
     #  better be too early than to late
     minute = ceil(minute / 5)
     self._select_meth(minute)
     led.set(self._led_array)