Created
January 26, 2020 00:41
-
-
Save ccoxwell/82ce1c212085f7c22a7ae833ccb1807a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write your code here :-) | |
import board | |
import neopixel | |
import adafruit_dht | |
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.05, auto_write=False) | |
pixels.fill((0, 0, 0)) | |
pixels.show() | |
dht = adafruit_dht.DHT22(board.A2) | |
def getColor(remainder): | |
switcher = { | |
0: (255, 0, 111), #brightpink | |
1: (255, 85, 0), #brightorange | |
2: (255, 213, 0), #yelloworange | |
3: (242, 255, 0), #yellow | |
4: (195, 255, 0), #yellowgreen | |
5: (0, 255, 30), #green | |
6: (0, 255, 213), #greenblue | |
7: (0, 204, 255), #lightblue | |
8: (0, 128, 255), #blue | |
9: (136, 0, 255), #violet | |
} | |
return switcher[remainder] | |
while True: | |
try: | |
humidity = round(dht.humidity) | |
tens = int(humidity / 10) | |
remainder = int(humidity % 10) | |
print(humidity) | |
print(tens) | |
print(remainder) | |
for i in range (0, tens, 1): | |
pixels[i] = (255, 255, 255) | |
if tens < 9: | |
for i in range (tens, 10, 1): | |
pixels[i] = getColor(remainder) | |
pixels.show() | |
except RuntimeError: | |
pass | |
except IndexError: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment