Am I right in understanding that the PWM pins are the only pins that can be controlled for fading?
I found the code below that manages to fade all pins (which is excellent) but after running the fade I would like to start blinking other pins at different times. Is it possible to merge the below code into a blink code that will allow me to blink other pins after the fade?
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
const byte pwmPin = 9;
const byte maxPin = 19;
ISR (PCINT0_vect)
{
if (PINB & _BV (1)) // D9
PORTB = PORTC = PORTD = 0xFF;
else
PORTB = PORTC = PORTD = 0;
}
void setup()
{
for (byte i = 0; i <= maxPin; i++)
pinMode (i, OUTPUT);
// pin change interrupt
PCMSK0 = _BV (PCINT1); // only want pin 9
PCIFR = _BV (PCIF0); // clear any outstanding interrupts
PCICR |= _BV (PCIE0); // enable pin change interrupts for PCINT7..0
} // end of setup
void loop()
{
// set the brightness of pin 9:
analogWrite(pwmPin, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255)
fadeAmount = -fadeAmount ;
// wait for 30 milliseconds to see the dimming effect
delay(30);
} // end of loop