Arduino icon indicating copy to clipboard operation
Arduino copied to clipboard

Full consolidation of "phase locking" and "PWM locking" waveform generators

Open dok-net opened this issue 4 years ago • 0 comments

This now needs review and testing. At time of publishing, the following MCVE works for eyes and ears, not tested with an oscilloscope by myself yet:

#include <PolledTimeout.h>

#ifndef D5
#define D5 (14)
#endif

uint8_t brightness = 255;
uint8_t brightnessAdj = 1;

void setup()
{
    tone(D5, 440, 3 * 2560);
    analogWrite(LED_BUILTIN, brightness);
}

esp8266::polledTimeout::periodicMs changeBrightness(10);

void loop()
{
    if (changeBrightness)
    {
        if (!brightness || !static_cast<uint8_t>(~brightness))
        {
            brightnessAdj = ~brightnessAdj;
            ++brightnessAdj;
        }
        brightness += brightnessAdj;
        analogWrite(LED_BUILTIN, brightness);
    }
}

Fixes #8081.

dok-net avatar May 01 '21 12:05 dok-net