Skip to content

Commit fa07f7f

Browse files
authored
Merge pull request #320 from brentru/io-house-1-patch
IO Home #1: Switch to adafruit_circuitpython_neopixel library
2 parents 17004db + 819e86e commit fa07f7f

File tree

1 file changed

+22
-34
lines changed

1 file changed

+22
-34
lines changed

IO_House_Series/Lights_and_Temp/io_house_light_temp.py

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,32 @@
1313
(https://github.com/adafruit/Adafruit_Blinka)
1414
- Adafruit_CircuitPython_SI7021
1515
(https://github.com/adafruit/Adafruit_CircuitPython_SI7021)
16-
- RPi WS281x Python
17-
(https://github.com/rpi-ws281x/)
16+
- Adafruit_CircuitPython_NeoPixel
17+
(https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel)
1818
"""
1919
# Import standard python modules
2020
import time
2121

2222
# import Adafruit IO REST client
23-
from Adafruit_IO import Client, Feed, RequestError
23+
from Adafruit_IO import Client
2424

2525
# import Adafruit Blinka
2626
from busio import I2C
27-
from board import SCL, SDA
27+
from board import SCL, SDA, D18
2828

2929
# import Adafruit_CircuitPython_Si7021 Library
3030
import adafruit_si7021
3131

3232
# import neopixel library
3333
import neopixel
3434

35-
# while True loop delay, in seconds
35+
# `while True` loop delay, in seconds
3636
DELAY_TIME = 5
3737

38-
# LED strip configuration:
39-
STRIP_LED_COUNT = 34 # Number of LED pixels on the NeoPixel Strip
40-
JEWEL_PIXEL_COUNT = 7 # Number of LED pixels on the NeoPixel Jewel
41-
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
42-
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
43-
LED_DMA = 10 # DMA channel to use for generating signal (try 10)
44-
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
45-
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
46-
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
47-
48-
# Create NeoPixel object with appropriate configuration.
49-
strip = neopixel.Adafruit_NeoPixel(STRIP_LED_COUNT, LED_PIN, LED_FREQ_HZ,
50-
LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
51-
# Intialize the library (must be called once before other functions).
52-
strip.begin()
38+
# number of LED pixels on the NeoPixel Strip
39+
STRIP_LED_COUNT = 34
40+
# number of LED pixels on the NeoPixel Jewel
41+
JEWEL_PIXEL_COUNT = 7
5342

5443
# Set to your Adafruit IO key.
5544
# Remember, your key is a secret,
@@ -64,23 +53,22 @@
6453
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
6554

6655
# set up Adafruit IO feeds
67-
try:
68-
temperature = aio.feeds('temperature')
69-
humidity = aio.feeds('humidity')
70-
outdoor_lights = aio.feeds('outdoor-lights')
71-
indoor_lights = aio.feeds('indoor-lights')
72-
except RequestError:
73-
temperature = aio.create_feed(Feed(name='temperature'))
74-
humidity = aio.create_feed(Feed(name='humidity'))
75-
outdoor_lights = aio.create_feed(Feed(name='outdoor-lights'))
76-
indoor_lights = aio.create_feed(Feed(name='indoor-lights'))
56+
temperature = aio.feeds('temperature')
57+
humidity = aio.feeds('humidity')
58+
outdoor_lights = aio.feeds('outdoor-lights')
59+
indoor_lights = aio.feeds('indoor-lights')
7760

7861
# create an i2c interface object
7962
i2c = I2C(SCL, SDA)
8063

8164
# instanciate the sensor object
8265
sensor = adafruit_si7021.SI7021(i2c)
8366

67+
# set up the NeoPixel strip
68+
pixels = neopixel.NeoPixel(D18, STRIP_LED_COUNT)
69+
pixels.fill((0,0,0))
70+
pixels.show()
71+
8472
print('Adafruit IO Home: Lights and Climate Control')
8573

8674
while True:
@@ -104,8 +92,8 @@
10492

10593
# set the jewel's color
10694
for i in range(JEWEL_PIXEL_COUNT):
107-
strip.setPixelColorRGB(i, green, red, blue)
108-
strip.show()
95+
pixels[i] = (red, green, blue)
96+
pixels.show()
10997

11098
# get the outdoor light color picker feed
11199
outdoor_light_data = aio.receive(outdoor_lights.key)
@@ -118,8 +106,8 @@
118106

119107
# set the strip color
120108
for j in range(JEWEL_PIXEL_COUNT, STRIP_LED_COUNT + JEWEL_PIXEL_COUNT):
121-
strip.setPixelColorRGB(j, green, red, blue)
122-
strip.show()
109+
pixels[j] = (red, green, blue)
110+
pixels.show()
123111

124112
# delay the loop to avoid timeout from Adafruit IO.
125113
time.sleep(DELAY_TIME)

0 commit comments

Comments
 (0)