|
13 | 13 | (https://github.com/adafruit/Adafruit_Blinka)
|
14 | 14 | - Adafruit_CircuitPython_SI7021
|
15 | 15 | (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) |
18 | 18 | """
|
19 | 19 | # Import standard python modules
|
20 | 20 | import time
|
21 | 21 |
|
22 | 22 | # import Adafruit IO REST client
|
23 |
| -from Adafruit_IO import Client, Feed, RequestError |
| 23 | +from Adafruit_IO import Client |
24 | 24 |
|
25 | 25 | # import Adafruit Blinka
|
26 | 26 | from busio import I2C
|
27 |
| -from board import SCL, SDA |
| 27 | +from board import SCL, SDA, D18 |
28 | 28 |
|
29 | 29 | # import Adafruit_CircuitPython_Si7021 Library
|
30 | 30 | import adafruit_si7021
|
31 | 31 |
|
32 | 32 | # import neopixel library
|
33 | 33 | import neopixel
|
34 | 34 |
|
35 |
| -# while True loop delay, in seconds |
| 35 | +# `while True` loop delay, in seconds |
36 | 36 | DELAY_TIME = 5
|
37 | 37 |
|
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 |
53 | 42 |
|
54 | 43 | # Set to your Adafruit IO key.
|
55 | 44 | # Remember, your key is a secret,
|
|
64 | 53 | aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
|
65 | 54 |
|
66 | 55 | # 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') |
77 | 60 |
|
78 | 61 | # create an i2c interface object
|
79 | 62 | i2c = I2C(SCL, SDA)
|
80 | 63 |
|
81 | 64 | # instanciate the sensor object
|
82 | 65 | sensor = adafruit_si7021.SI7021(i2c)
|
83 | 66 |
|
| 67 | +# set up the NeoPixel strip |
| 68 | +pixels = neopixel.NeoPixel(D18, STRIP_LED_COUNT) |
| 69 | +pixels.fill((0,0,0)) |
| 70 | +pixels.show() |
| 71 | + |
84 | 72 | print('Adafruit IO Home: Lights and Climate Control')
|
85 | 73 |
|
86 | 74 | while True:
|
|
104 | 92 |
|
105 | 93 | # set the jewel's color
|
106 | 94 | 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() |
109 | 97 |
|
110 | 98 | # get the outdoor light color picker feed
|
111 | 99 | outdoor_light_data = aio.receive(outdoor_lights.key)
|
|
118 | 106 |
|
119 | 107 | # set the strip color
|
120 | 108 | 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() |
123 | 111 |
|
124 | 112 | # delay the loop to avoid timeout from Adafruit IO.
|
125 | 113 | time.sleep(DELAY_TIME)
|
0 commit comments