// For the Discord channel.
// Not using a specific amount or bits for the possible pwm values,
// only the amount of microseconds.
//
// Update 3 November 2025:
// Leds that needs to be completely off,
// are no longer turned on at the start
// of the interval.
//
// The next project:
// https://wokwi.com/projects/446459090238017537
//
// 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.
// But keep the leds off that do not need
// to be turned on at all.
for (int i=0; i<3; i++)
if(Pulses[i] > 0)
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);
}
}
}
}