Something I learned about Feather Huzzah and RGB LED

I wanted to share something I discovered while experimenting with common anode RGB LED and Feather Huzzah. I was using an example sketch that was intended for an Arduino Uno using the analogWrite function. The example was based on duty cycle of 255 which is default for the function. When it ran the RGB LED did not change to the expected colors (Red, Green, Blue, Yellow, Purple then Aqua) but instead changed to few shades of lite blue. Initially thought the pins I was using (14, 12, and 13) were not capable of PWM but I found documentation that all but pin 16 are capable. I didn’t find any documentation on the Feather Huzzah that stated what its frequency is until I found the Adafruit IO sketch that showed using 1023. Voila.

/*
Adafruit Arduino - Lesson 3. RGB LED
  For Arduino PWM duty cycle is 0-255 but for Feather Huzzah its 0-1023
*/

int redPin = 14;
int greenPin = 12;
int bluePin = 13;

//uncomment this line if using a Common Anode LED
#define COMMON_ANODE

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);  
}

void loop()
{
  setColor(1023, 0, 0);  // red
  delay(1000);
  setColor(0, 1023, 0);  // green
  delay(1000);
  setColor(0, 0, 1023);  // blue
  delay(1000);
  setColor(1023, 1023, 0);  // yellow
  delay(1000);  
  setColor(80, 0, 80);  // purple
  delay(1000);
  setColor(0, 1023, 1023);  // aqua
  delay(1000);
}

void setColor(int red, int green, int blue)
{
  #ifdef COMMON_ANODE
    red = 1023 - red;
    green = 1023 - green;
    blue = 1023 - blue;
  #endif
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue);  
}

what its frequency is

Do not confuse frequency with range/resolution! The maximum value that analogWrite() can be given is the range, not the frequency.

On Huzzah and all esp8266 based boards, you can change the range, for example you can use

analogWriteRange(255);

in setup() to make your code behave as it would on Uno/Nano for example.

Unfortunately, this will not allow the same code to run on esp8266 or Uno because the analogWriteRange() function is not available on Uno etc. But you could put this in setup():

#if defined(ESP8266)
analogWriteRange(255);
#endif

Thanks for clarifying that for me and for pointing out the analogWriteRange function.