Toggle Navigation
Hatchery
Eggs
andzrave
dragon.py
Users
Badges
Login
Register
dragon.py
raw
Content
# imports from machine import Pin from neopixel import NeoPixel import display #import time import math brightness = 50 # brightness in % def lightup(pressed): if pressed: lightup_led def lightup_led(): # Pin 19 controls the power supply to SD card and neopixels powerPin = Pin(19, Pin.OUT) # Pin 5 is the LED's data line dataPin = Pin(5, Pin.OUT) # create a neopixel object for 5 pixels np = NeoPixel(dataPin, 5) # turn on power to the LEDs powerPin.on() # set some colors for the pixels (RGB) np[0] = list(map(bri, [255,0,0])) # RED np[1] = list(map(bri, [0,255,0])) # GREEN np[2] = list(map(bri, [0,0,255])) # BLUE np[3] = list(map(bri, [255,255,0])) # YELLOW np[4] = list(map(bri, [255,0,255])) # MAGENTA # send colors out to LEDs np.write() def lightdown_led(): # Pin 19 controls the power supply to SD card and neopixels powerPin = Pin(19, Pin.OUT) # Pin 5 is the LED's data line dataPin = Pin(5, Pin.OUT) # create a neopixel object for 5 pixels np = NeoPixel(dataPin, 5) # turn on power to the LEDs powerPin.off() # set some colors for the pixels (RGB) np[0] = list(map(bri, [255,0,0])) # RED np[1] = list(map(bri, [0,255,0])) # GREEN np[2] = list(map(bri, [0,0,255])) # BLUE np[3] = list(map(bri, [255,255,0])) # YELLOW np[4] = list(map(bri, [255,0,255])) # MAGENTA # send colors out to LEDs np.write() def brightup_btn(pressed): if pressed: brightup() def brightup(): global brightness brightness = (brightness + 10) % 100 lightup_led() def brightdown_btn(pressed): if pressed: brightdown() def brightdown(): global brightness brightness = (brightness - 10) % 100 lightup_led() def brightanimation(pressed): if pressed: global brightness b = [round(100 * pow(math.sin(math.radians(x * 9 / 2)), 2)) for x in range(40)] for i in range(40): brightness = b[i] lightup_led() #time.sleep(0.2) def bri(pos): pos = round(pos/100* brightness) return pos