#include "SoftwarePWM.h"
int dir;
int dutyCycle;
unsigned long timer;
uint8_t pins [10] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
SoftwarePWM swPWM(pins, 10);
ISR(TIMER1_OVF_vect) {
swPWM.refresh();
}
void setup()
{
TCCR1A = 0;
TCCR1B = 0;
TCCR1A |= (1 << WGM11);
TCCR1B |= (1 << CS10) | (1 << WGM13);
TIMSK1 |= (1 << TOIE1);
ICR1 = 4000; // Adjusted for simulation.
}
void loop()
{
unsigned long now = millis();
if (now - timer > 10)
{
for (int i = 0; i < 10; ++i)
{
if (dir == 1)
{
if (dutyCycle < 255)
{
dutyCycle++;
}
else
{
dir = 0;
}
}
else
{
if (dutyCycle > 0)
{
dutyCycle--;
}
else
{
dir = 1;
}
}
swPWM.setDutyCycle(i, dutyCycle);
}
timer = now;
}
}