// For the Discord channel.
// Not using a specific amount or bits for the possible pwm values,
// only the amount of microseconds.
// Interval in microseconds
unsigned long timerInterval = 2000;
unsigned long Pulses[3] = { 1000UL, 1500UL, 100UL };
unsigned long previousMicros;
const int leds[3] = {3, 5, 6};
void setup()
{
Serial.begin(115200);
Serial.println(F("Software PWM"));
for (int i = 0; i < 3; i++) {
pinMode(leds[i], OUTPUT);
}
}
void loop()
{
unsigned long currentMicros = micros();
if(currentMicros - previousMicros >= timerInterval)
{
// Time is up for this interval.
previousMicros = currentMicros;
// Turn on all leds for the new interval.
for (int i=0; i<3; i++)
digitalWrite(leds[i],HIGH);
}
else
{
// Check if a led has to be turned off.
for (int i=0; i<3; i++)
{
if(currentMicros - previousMicros >= Pulses[i])
{
digitalWrite(leds[i],LOW);
}
}
}
}