from machine import PWM, Pin, Timer,ADC
import time
load = PWM(Pin(0))
load.freq(1000) # f = 1000Hz to reduce ripple
# load.duty_u16(32767) # 50%
# Q1
# n = 0
# def fn(timer):
# global n
# load.duty_u16((65535 // 10) * n)
# n += 1
# n = n % 11 # Reset n when it reaches 11
# Q2
# adc=ADC(0)
# def fn(timer):
# brightness=adc.read_u16()
# load.duty_u16(brightness)
# Q3
bar_graph = [Pin(i, Pin.OUT) for i in range(1, 11)]
def update_led_bar(value):
for i in range(10):
if i < value:
bar_graph[i].high() # Turn on the LED
else:
bar_graph[i].low() # Turn off the LED
update_led_bar(10)
# t = Timer(period=1000, mode=Timer.PERIODIC, callback=fn)