Open 4.3Brightness_adjustment.py and click.
'''
* Filename : Brightness_adjustment
* Thonny : Thonny 4.1.4
* Auther : http//www.keyestudio.com
'''
from machine import Pin,ADC,PWM
import time
RP = ADC(26)
led = PWM(Pin(11))
led.freq(1000)
while True:
RP_Value = RP.read_u16()
print('ADC Value:',RP_Value)
led.duty_u16(RP_Value)
time.sleep(0.1)
from machine import Pin,ADC,PWM
import PIN, ADC, PWM module.
led = PWM(Pin(11))
a PWM function whose PWM output pin is io11.
led.freq(1000)
Set PWM output frequency to 1000Hz.
led.duty_u16(RP_Value)
Set duty cycle, set the value output by the potentiometer to the duty cycle of the white LED module.
Conceive:
Initialization: set the pins of potentiometer and white LED module, set the output frequency of the LED module.
Loop:
① Read the ADC value of potentiometer, and print it on Shell.
② Set the value as the duty cycle of white LED module, so that the potentiometer controls the brightness of LED.