import time
from machine import Pin as pin, ADC, PWM
time.sleep(0.1) # Wait for USB to become ready
pin(23, pin.OUT).value(1) #Sets internal pin 23 to HIGH so the analog read gets a lil bit cleaner
pot = ADC(pin(26))
led_pwm = PWM(pin(8))
frequency = 5000
led_pwm.freq (frequency)
#Ejercicio 1
# while True:
# analog_value = pot.read_u16()
# print('Value:',analog_value)
# time.sleep(0.3)
#Ejercicio 2
# while True:
# analog_value = pot.read_u16()
# value_fifty_perc = int(analog_value*0.5)
# value_three_hundred_perc = analog_value*3
# print('100%:',analog_value,' --- ','50%:',value_fifty_perc,' --- ','300%:',value_three_hundred_perc)
# time.sleep(0.3)
#Ejercicio 3
max_brightness = 65536
min_brightness = int(max_brightness*0.25) #25% of the PWM range
duty_step = int(max_brightness*0.05) #5% of the PWM range
while True:
for i in range(min_brightness,max_brightness,duty_step):
led_pwm.duty_u16(i)
print('PWM Value: ',i)
time.sleep(2)