from time import sleep
from machine import Pin
from machine import PWM
# ====================
# Set up LED pin
# ====================
# Pin setup for
led = PWM(Pin(0))
led.freq(1000)
# Note: We can easily set how fast the led goes
# from MIN to MAX by setting an increment
MIN_LIGHT = 0
MAX_LIGHT = 65025
INC_LIGHT = 5000
# This function just sets the current brightness of the led
# and pauses for .25 seconds
def setLedCycle(brightness):
led.duty_u16(brightness)
print(f"Brightness: {brightness}")
sleep(.25)
while True:
# Incrementally brighten the light by INC_LIGHT from MIN_LIGHT to MAX_LIGHT
for brightness in range(MIN_LIGHT, MAX_LIGHT, INC_LIGHT):
setLedCycle(brightness)
print(f"Brightness +: {brightness}")
# We darken the light by INC_LIGHT from MAX_LIGHT to MIN_LIGHT
for brightness in range(MAX_LIGHT, MIN_LIGHT , -INC_LIGHT):
setLedCycle(brightness)
print(f"Brightness -: {brightness}")
print("Starting up")