PWM 관련 register 1
PWM 관련 register 2
led_gradation.ino 다시쓰기
int val = 0; // variable to store the read value void setup() { DDRD = _BV(DDD6); // sets the pin as output (pin 6) TCCR0A = _BV(COM0A1) | _BV(WGM01) | _BV(WGM00); TCCR0B = _BV(CS01) | _BV(CS00); } void loop() { delay(5); val += 1; OCR0A = val; // analogWrite values from 0 to 255 if(val >= 256) val = 0; }
참고자료
- Arduino - Secrets Of Arduino PWM
- Atmel AVR 328p datasheet - 15. 8-bit Timer/Counter0 with PWM