Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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