Advertisement
glerium

ADC控制LED亮度

Oct 22nd, 2022 (edited)
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. from machine import Pin,ADC,PWM
  2. import time
  3. tmp = Pin(12,Pin.IN)
  4. adc = ADC(Pin(14))
  5. pwm = PWM(Pin(32,Pin.OUT))
  6. adc.atten(ADC.ATTN_11DB)
  7. adc.width(ADC.WIDTH_10BIT)
  8. pwm.freq(100000)
  9. while True:
  10.     val = adc.read()
  11.     print('{:.1f}'.format(val*1.4))
  12.     pwm.duty(int(min(val*1.4,1023)))
  13.     time.sleep_ms(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement