---
# System prepended metadata

title: 亮度控制LED

---

# 亮度控制LED
## Description

利用光感測器亮度感應來控制LED
亮度亮 --〉 LED 暗
亮度暗 --〉 LED 亮 

## Code
```python=
from machine import Pin, ADC, PWM, Timer

#光敏電阻設定
ADC(Pin(39)).atten(ADC.ATTN_6DB)
#LED設定
pwm16 = PWM(Pin(16),freq=1000,duty=0)

def LED(t):
    pwm16.duty(1023-ADC(Pin(39)).read())
Timer(0).init(period=100, callback=LED)

```
