16-bit PWM on Arduino Leonardo Pro Micro

First, dimming a led lamp using 8-bit regular analogWrite().

And here, 16-bit pwm by writing directly to the registers.

Below is the source code (adapted from http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on-your)

#define LED OCR1A // pin 9 (our led pin)

void setup() {
    // pin 9 is one of the 16-bit PWM pins on the Pro Micro
    pinMode(9, OUTPUT);

    // Do something I don't really understand
    ICR1 = 0xFFFF;
    TCCR1A = 0b10101010;
    TCCR1B = 0b00011001;

    // Set the led to 0 brightness
    LED = 0;

unsigned int temp = 0;

void loop() {
    LED = temp; //set brightness, equivalent to analogWrite but now with 16-bit
    temp++; //temp should be from 0-65535

Comments are Disabled