More fun with LEDs! I took the Energia LED fader example from energia.nu and modified it to output to P1.4, P1.5, P1.6 and P1.7 so that all four LEDs would fade in sync.
#include "Energia.h"
void setup();
void loop();
/*
http://energia.nu/Tutorial_Fade.html
Fade
This example shows how to fade LEDs on pins (P1.4 thru P1.7)
using the analogWrite() function.
This example code is in the public domain.
*/
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
// declare pins P1_4 through P1_7 to be outputs:
pinMode(P1_4, OUTPUT);
pinMode(P1_5, OUTPUT);
pinMode(P1_6, OUTPUT);
pinMode(P1_7, OUTPUT);
}
void loop() {
// set the brightness of the LEDs:
analogWrite(P1_4, brightness);
analogWrite(P1_5, brightness);
analogWrite(P1_6, brightness);
analogWrite(P1_7, 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);
}
Problem: it doesn't work. Or rather, P1.6 fades in and out as it should, but P1.4, P1.5 and P1.7 just turn on and off.
If I change the original Energia code example to fade P1.5 instead of P1.6, the same thing happens: the LED just turns on and off.
I've looked all over for a statement saying that Energia's AnalogWrite only works on P1.6, but have found nothing. What gives -- is my code broken?
Thanks!