Exemplo n.º 1
0
 def ledProc(self):
     if self.is_initialized:
         ledState = 0
         ledData = [0x00, 0x00, 0x00] * 12
         while True:
             for i in range(len(ledData)):
                 if ledData[i] > 64:
                     ledData[i] -= 64
                 else:
                     ledData[i] = 0
                 time_full = self.rtc.now()
                 hours = int(time_full[3]) % 12
                 minutes = int(time_full[4] / 5)
                 seconds = int(time_full[5] / 5)
                 if self.running:
                     for i in range(12):
                         # blue = 0xff if seconds // 5 == i else 0
                         # green = 0xff if minutes // 5 == i else 0
                         # red = 0xff if hours % 12 == i else 0
                         green = 0xff if i == (11 - minutes) else 0x00
                         blue = 0xff if i == (11 - seconds) else 0x00
                         red = 0xff if i == (11 - hours) else 0x00
                         ledData[3 * i] = green >> self.dimmer
                         ledData[3 * i + 1] = red >> self.dimmer
                         ledData[3 * i + 2] = blue >> self.dimmer
                 neopixel.send(bytes(ledData))
                 ledState = ledState + 1
                 if ledState > 254:
                     ledState = 0
                 time.sleep_ms(20)
Exemplo n.º 2
0
def setLed(l,r,u,d,z1,z2,gl,gr,gu,gd,gz1,gz2):
	data = [0x00, 0x00, 0x00]*25
	for i in range(3):
		data[(i+21)*3] = l
		data[(i+1)*3] = r
		data[((i+1)*5)*3] = u
		data[(((i+1)*5)+4)*3] = d
		
	data[12*3+1] = z1
	data[12*3+2] = z2
	
	data[7*3+1] = gd
	data[17*3+1] = gu
	
	data[11*3+1] = gl
	data[13*3+1] = gr
	
	data[0*3+1] = gz1
	data[4*3+1] = gz1
	data[20*3+1] = gz1
	data[24*3+1] = gz1
	data[0*3+2] = gz2
	data[4*3+2] = gz2
	data[20*3+2] = gz2
	data[24*3+2] = gz2
		
	neopixel.send(bytes(data))
Exemplo n.º 3
0
def ledThread():
	ledValue = 4
	ledDirection = False
	global flashlightStatus, stopThreads
	while not stopThreads:
		if neopixel:
			if (not flashlightStatus):
				neopixel.send(bytes([0, 4+ledValue, 0]*5 + [0, 4+24-ledValue, 0]*7))
			if ledDirection:
				ledValue -=2
				if ledValue <= 0:
					levValue = 0
					ledDirection = False
			else:
				ledValue += 6
				if ledValue >= 24:
					levValue = 24
					ledDirection = True
		if samd:
			for i in range(6):
				samd.led(i, (ledValue == i)*255, (ledValue < i)*255, (ledValue > i)*255)
			if ledDirection:
				ledValue -= 1
				if ledValue <= 0:
					levValue = 0
					ledDirection = False
			else:
				ledValue += 1
				if ledValue >= 6:
					levValue = 6
					ledDirection = True
			
		time.sleep_ms(60)
Exemplo n.º 4
0
def prepareForSleep():
	try:
		os.umountsd()
	except:
		pass
	neopixel.send(bytes([0]*24)) # Turn off LEDs
	configureWakeupSource()
def toggleLeds(pressed):
    global ledState
    if pressed:
        ledState = not ledState
        if ledState:
            neopixel.send(bytes([0xFF, 0xFF, 0xFF] * 12))
        else:
            neopixel.send(bytes([0, 0, 0] * 12))
Exemplo n.º 6
0
def cbSleep(idleTime=None):
    global stopThreads
    neopixel.send(bytes([0x00] * 3 * 12))
    if idleTime == None:
        idleTime = virtualtimers.idle_time()
    gui_redraw = True
    stopThreads = True
    drawTask(True)
    display.flush()
    time.sleep(0.1)
    system.sleep(idleTime, True)
Exemplo n.º 7
0
def cbSleep(idleTime=None):
    global ledTask, scrollerTask
    neopixel.send(bytes([0x00] * 3 * 12))
    if idleTime == None:
        idleTime = virtualtimers.idle_time()
    gui_redraw = True
    virtualtimers.delete(scrollerTask)
    virtualtimers.delete(ledTask)
    display.windowHide("scroller")
    drawTask(True)
    display.flush()
    time.sleep(0.1)
    system.sleep(idleTime, True)
Exemplo n.º 8
0
 def __init__(self):
     self.running = True
     self.dimmer = 2
     self.rtc = machine.RTC()
     display_connecting()
     wifi.connect()
     if not wifi.wait():
         system.launcher()
     if wifi.status():
         display_connected(["Dimmer: %d (lf,rt)" % self.dimmer])
         self.sync_ntp(True)
         self.is_initialized = True
     else:
         ledData = [0x00, 0x00, 0x00, 0x00, 0x79, 0x00] * 6
         neopixel.send(bytes(ledData))
         system.launcher()
Exemplo n.º 9
0
def ledTask():
    global ledValue, ledDirection
    if not flashlightStatus:
        neopixel.send(
            bytes([0, 4 + ledValue, 0] * 5 + [0, 4 + 24 - ledValue, 0] * 7))
    if ledDirection:
        ledValue -= 2
        if ledValue <= 0:
            levValue = 0
            ledDirection = False
    else:
        ledValue += 6
        if ledValue >= 24:
            levValue = 24
            ledDirection = True
    return 25
Exemplo n.º 10
0
def ledThread():
    ledValue = 4
    ledDirection = False
    global stopThreads
    while not stopThreads:
        neopixel.send(bytes([0, ledValue, 0] * 6))
        if ledDirection:
            ledValue -= 2
            if ledValue <= 0:
                levValue = 0
                ledDirection = False
        else:
            ledValue += 6
            if ledValue >= 24:
                levValue = 24
                ledDirection = True
        time.sleep_ms(100)
Exemplo n.º 11
0
def ledThread():
	ledValue = 4
	ledDirection = False
	global flashlightStatus, stopThreads
	while not stopThreads:
		if not flashlightStatus:
			neopixel.send(bytes([0, 4+ledValue, 0]*5 + [0, 4+24-ledValue, 0]*7))
		if ledDirection:
			ledValue -=2
			if ledValue <= 0:
				levValue = 0
				ledDirection = False
		else:
			ledValue += 6
			if ledValue >= 24:
				levValue = 24
				ledDirection = True
		time.sleep_ms(30)
Exemplo n.º 12
0
def cbFlashlight(pressed):
	global led_app, flashlightStatus
	if pressed and neopixel:
		if flashlightStatus:
			pm.enable()
			neopixel.send(bytes([0x00]*3*12))
		else:
			pm.disable()
			neopixel.send(bytes([0xFF]*3*12))

		if led_app:
			try:
				if flashlightStatus:
					led_app.resume()
				else:
					led_app.pause()
			except:
				pass
		flashlightStatus = not flashlightStatus
Exemplo n.º 13
0
def setSmiley(r,g):
	data = [0x00, 0x00, 0x00]*25

	data[5*3+0] = g
	data[5*3+1] = r
	data[15*3+0] = g
	data[15*3+1] = r

	data[8*3+0] = g
	data[8*3+1] = r
	data[13*3+0] = g
	data[13*3+1] = r
	data[18*3+0] = g
	data[18*3+1] = r

	data[2*3+0] = g
	data[4*3+1] = r
	
	data[22*3+0] = g
	data[24*3+1] = r
	
	
	
	neopixel.send(bytes(data))
Exemplo n.º 14
0
 def _neopixels_off(self):
     data = [0x00, 0x00, 0x00, 0x00] * NUM_NEOPIXELS
     neopixel.send(bytes(data))
     self._neopixels = False
Exemplo n.º 15
0
mpr121.set(10, 1)  # Calibration resets MPR121, here we re-enable LED power

buzzer_pin = machine.Pin(12, machine.Pin.OUT)
time.sleep(0.01)
buzzer_pwm = machine.PWM(buzzer_pin, duty=50)

sndmixer.begin(2)
synth = sndmixer.synth()
sndmixer.volume(synth, 50)
sndmixer.waveform(synth, 1)

while True:
    buzzer_pwm.duty(50)
    buzzer_pwm.freq(500)
    sndmixer.freq(synth, 500)
    neopixel.send(bytes([0xFF, 0, 0] * 12))
    time.sleep(0.25)
    buzzer_pwm.freq(600)
    sndmixer.freq(synth, 600)
    neopixel.send(bytes([0, 0xFF, 0] * 12))
    time.sleep(0.25)
    buzzer_pwm.freq(800)
    sndmixer.freq(synth, 800)
    neopixel.send(bytes([0, 0, 0xFF] * 12))
    time.sleep(0.25)
    buzzer_pwm.freq(500)
    sndmixer.freq(synth, 500)
    neopixel.send(bytes([0xFF, 0, 0] * 12))
    time.sleep(0.25)
    buzzer_pwm.freq(600)
    sndmixer.freq(synth, 600)
Exemplo n.º 16
0
from time import sleep
from umqtt.simple import MQTTClient
import urandom
import utime
import wifi

from .bme280_float import BME280
from .mhz19 import MHZ19

CO2_THRESHOLD_NOTICE = 600
CO2_THRESHOLD_WARNING = 800
CO2_THRESHOLD_CRITICAL = 1600

# Activate LEDs to also switch on 5V power supply to the MH-Z19.
neopixel.enable()
neopixel.send(bytes(4 * 6 * [0]))

i2c = I2C(sda=Pin(26), scl=Pin(27))
bme280 = BME280(i2c=i2c)


def clear_rect(rect):
    x, y, w, h = rect
    display.drawRect(x, y, w, h, True, 0xffffff)


def draw_dashed_line(x0, y0, x1, y1, color=0x000000, space=12):
    vx, vy = x1 - x0, y1 - y0
    l2 = sqrt(vx**2 + vy**2)
    vec_x, vec_y = vx / l2 * space, vy / l2 * space
Exemplo n.º 17
0
def leds_send_data(data, length=0):
	neopixel.send(data)
Exemplo n.º 18
0
# https://docs.badge.team/esp32-app-development/api-reference/neopixel/

# Enable neopixel and set pin (19) in config.h

print('Test: Neopixel SK9822 RGBW LEDs')

import neopixel
from time import sleep

neopixel.enable()

neopixel.send(
    bytes([1, 0, 0, 0] + [0, 1, 0, 0] + [0, 0, 1, 0] + [0, 1, 1, 0] +
          [0, 0, 0, 1]))
sleep(0.25)
neopixel.send(bytes([0, 0, 0, 0] * 5))
sleep(0.25)
neopixel.send(bytes([0, 1, 0, 0] * 5))
sleep(0.25)
neopixel.send(bytes([0, 0, 1, 0] * 5))
sleep(0.25)
neopixel.send(bytes([0, 0, 0, 1] * 5))
sleep(0.25)
neopixel.send(bytes([0, 0, 0, 0] * 5))

neopixel.disable()  # disable, not aufhoeren zu leuchten

print('done')
Exemplo n.º 19
0
 def _neopixels_pink(self):
     data = [0x00, 0x10, 0x10, 0x00] * NUM_NEOPIXELS
     neopixel.send(bytes(data))
     self._neopixels = True
Exemplo n.º 20
0
def cbStartLauncher(pressed):
    if pressed:
        global stopThreads
        stopThreads = True
        neopixel.send(bytes([0x00] * 3 * 12))
        system.launcher(False)