adding support for circuitpython neopixel library, linted

This commit is contained in:
brentru 2018-09-05 16:49:17 -04:00
parent 4241b62961
commit 37195378d7

View file

@ -13,28 +13,32 @@ Dependencies:
(https://github.com/adafruit/Adafruit_Blinka)
- Adafruit_CircuitPython_SGP30
(https://github.com/adafruit/Adafruit_CircuitPython_SGP30)
- Adafruit_CircuitPython_NeoPixel
(https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel)
- picamera
(https://github.com/waveform80/picamera)
"""
# Import standard python modules
import time
import base64
import os
# import Adafruit IO REST client
from Adafruit_IO import Client, Feed, RequestError
from Adafruit_IO import Client, RequestError
# import SGP30, NeoPixel and picam libraries
import neopixel
import adafruit_sgp30
import picamera
# import Adafruit Blinka
from board import SCL, SDA, D18, D22, D24
from busio import I2C
import digitalio
import neopixel_write
# import Adafruit_CircuitPython_SGP30 and picam
import adafruit_sgp30
import picamera
# NeoPixels Commands
PIXELS_OFF = bytearray([0, 0, 0])
PIXELS_ON = bytearray([0, 255, 0])
# Number of NeoPixels connected to the strip
NUM_PIXELS_STRIP = 60
# Number of NeoPixels connected to the NeoPixel Jewel
NUM_PIXELS_JEWEL = 6
RED = (255, 0, 0)
# Set to the hour at which to arm the alarm system, 24hr time
ALARM_HOUR = 16
@ -85,23 +89,24 @@ i2c_bus = I2C(SCL, SDA, frequency=100000)
sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c_bus)
# set up the neopixel strip
pixel_strip = digitalio.DigitalInOut(D18)
pixel_strip.direction = digitalio.Direction.OUTPUT
neopixel_write.neopixel_write(pixel_strip, PIXELS_OFF)
print('Adafruit IO Home: Security')
pixels = neopixel.NeoPixel(D18, NUM_PIXELS_STRIP)
pixels.fill((0, 0, 0))
pixels.show()
def alarm_trigger():
"""Alarm is triggered by the dashboard toggle
and a sensor detecting movement.
"""
print('* SYSTEM ALARM!')
for j in range(0, 5):
neopixel_write.neopixel_write(pixel_strip, PIXELS_ON)
for j in range(NUM_PIXELS_JEWEL):
pixels[j] = RED
pixels.show()
time.sleep(0.5)
neopixel_write.neopixel_write(pixel_strip, PIXELS_OFF)
# turn pixels off after alarm animation
neopixel_write.neopixel_write(pixel_strip, PIXELS_OFF)
# turn pixels off after alarm
pixels.fill((0, 0, 0))
pixels.show()
print('Adafruit IO Home: Security')
while True:
# read SGP30
@ -144,20 +149,18 @@ while True:
try:
aio.send(picam_feed.key, send_str)
print('sent to AIO!')
except:
except RequestError:
print('Sending camera image failed...')
# Alarm System
is_alarm = aio.receive(alarm_feed.key)
if (is_alarm.value == "ON"):
if is_alarm.value == "ON":
# sample the current hour
cur_time = time.localtime()
cur_hour = time.tm_hour
if (cur_hour > ALARM_HOUR and is_pir_activated == True):
if (cur_hour > ALARM_HOUR and is_pir_activated is True):
alarm_trigger()
prev_pir_value = door_sensor.value
time.sleep(LOOP_INTERVAL)