Arduino Code

NeoPixels

You can use Arduino to control the NeoPixels connected via the snap-in NeoPixel connector on the Prop-Maker FeatherWing.

To use NeoPixels with the Prop-Maker FeatherWing, install the Adafruit NeoPixel library from the Arduino Library Manager.

This example lights up a 30-pixel NeoPixel strip with a rainbow pattern. Change NUM_PIXELS to match the number of NeoPixels you've connected to your FeatherWing.

/*
* Adafruit Prop-Maker Featherwing
* NeoPixel Example
* 
* Rainbow example for 30-Pixel NeoPixel Strip
*/
#include <Adafruit_NeoPixel.h>

// NeoPixel strip length, in pixels
#define NUM_PIXELS 30

#if defined(__SAMD21G18A__) || defined(__AVR_ATmega32U4__)
  #define NEOPIXEL_PIN 5
  #define POWER_PIN    10
#elif defined(__AVR_ATmega328P__)
  #define NEOPIXEL_PIN 5
  #define POWER_PIN    10
#elif defined(NRF52)
  #define NEOPIXEL_PIN 27
  #define POWER_PIN    11
#elif defined(ESP8266)
  #define NEOPIXEL_PIN 2
  #define POWER_PIN    15
#elif defined(TEENSYDUINO)
  #define NEOPIXEL_PIN 8
  #define POWER_PIN    10
#elif defined(ESP32)
  #define NEOPIXEL_PIN 14
  #define POWER_PIN    33
#endif

// create a neopixel strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);


void setup() {
  Serial.begin(115200);
  Serial.println("\nProp-Maker Wing: NeoPixel");

  // Set power pin to output
  pinMode(POWER_PIN, OUTPUT);
  // Disable the pin, we're not currently writing to the neopixels.
  digitalWrite(POWER_PIN, LOW);

  // This initializes the NeoPixel library.
  strip.begin();
}


uint32_t Wheel(byte WheelPos) {
  // Input a value 0 to 255 to get a color value.
  // The colours are a transition r - g - b - back to r.
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    // turn on the Prop-Maker FeatherWing's power pin
    digitalWrite(POWER_PIN, HIGH);
    // write the pixel values
    strip.show();
    delay(wait);
  }
}

void loop()
{
  // cycle a the rainbow with a 20ms wait
  rainbow(20);
}

For more information on using NeoPixels, check out the Adafruit NeoPixel Überguide!

Audio

While technically the Feather M0 and M4 have an analog output pin that is connected to the amplifier on this Wing, Arduino does not have great audio playback support. So we don't recommend using Arduino if you need to play audio.

If you'd like to use the Adafruit Prop-Maker FeatherWing's Audio capabilities, check out the CircuitPython code.

Other than the M0 and M4 series, most Feathers don't have analog out on A0 at all, so you wouldn't be able to use this feature anyways.

Accelerometer

You can easily access the acceleration data from the LIS3DH accelerometer in the center of the Prop-Maker FeatherWing using Arduino.

To use the Accelerometer on the Prop-Maker FeatherWing, you'll need to install two Arduino Libraries. 

First, install the Adafruit LIS3DH library from the Arduino Library Manager.

Then, install the Adafruit Unified Sensor Library from the Arduino Library Manager: 

This example prints the acceleration data to the serial monitor. Move the board around to see the values change.

The LIS3DH can also detect taps - quickly tap the Prop-Maker FeatherWing to display a tap on the Serial Monitor.

/*
* Adafruit Prop-Maker Featherwing
* Accelerometer Example
* 
* Prints acceleration data to the Serial Monitor
*/
// include the accelerometer library
#include <Adafruit_LIS3DH.h>

// Adjust this number for the sensitivity of the 'click' force
// this strongly depend on the range! for 16G, try 5-10
// for 8G, try 10-20. for 4G try 20-40. for 2G try 40-80
#define CLICKTHRESHHOLD 40

// inst. i2c accelerometer
Adafruit_LIS3DH lis = Adafruit_LIS3DH();

void setup() {
  Serial.begin(115200);
  Serial.println("\nProp-Maker Wing: Accelerometer");

  Serial.println("Starting LIS3DH...");
  if (! lis.begin(0x18)) {   // change this to 0x19 for alternative i2c address
    Serial.println("Couldnt start LIS3DH");
    while (1);
  }
  Serial.println("LIS3DH Started!");

  // Set Accelerometer Range (2, 4, 8, or 16 G!)
  lis.setRange(LIS3DH_RANGE_4_G);

  /* Set Accelerometer Click Detection
  * 0 = turn off click detection & interrupt
  * 1 = single click only interrupt output
  * 2 = double click only interrupt output   
  * NOTE: Higher numbers are less sensitive
  */
  lis.setClick(1, CLICKTHRESHHOLD);

}

void loop() {

  // Detect a click 
  uint8_t click = lis.getClick();
  
  // Get a new accel. sensor event
  sensors_event_t event; 
  lis.getEvent(&event);
  
  /* Display the results (acceleration is measured in m/s^2) */
  Serial.print("\t\tX: "); Serial.print(event.acceleration.x);
  Serial.print(" \tY: "); Serial.print(event.acceleration.y); 
  Serial.print(" \tZ: "); Serial.print(event.acceleration.z); 
  Serial.println(" m/s^2 ");
  Serial.println();

  delay(1000); 
  
  // detect click
  if (click & 0x10) Serial.print(" single click");
}

3 Watt LED

You can control the colors and brightness of a 3 Watt RGB LED using Arduino.

This example uses PWM to light up the LED with a rainbow swirl.

Not all Feather boards have PWMs available on the RGB pins! If so you won't see a smooth color swirl.
/*
* Adafruit Prop-Maker Featherwing
* LED Example
* 
* Rainbow swirl example for 3W LED.
*/

#if defined(__SAMD21G18A__) || defined(__AVR_ATmega32U4__)
  // No green PWM on 32u4
  #define POWER_PIN    10
  #define RED_LED      11
  #define GREEN_LED    12  // no PWM on atmega32u4
  #define BLUE_LED     13
#elif defined(__AVR_ATmega328P__)
  // No Red or Blue PWM
  #define POWER_PIN    10
  #define RED_LED      2
  #define GREEN_LED    3  // the only PWM pin!
  #define BLUE_LED     4
#elif defined(NRF52)
  #define POWER_PIN    11
  #define RED_LED      7
  #define GREEN_LED    15
  #define BLUE_LED     16
#elif defined(ESP8266)
  #define POWER_PIN    15
  #define RED_LED      13
  #define GREEN_LED    12
  #define BLUE_LED     14
#elif defined(TEENSYDUINO)
  #define POWER_PIN    10
  #define RED_LED      9
  #define GREEN_LED    6
  #define BLUE_LED     5
#elif defined(ESP32)
  #define POWER_PIN    33
  #define RED_LED 0
  #define GREEN_LED 1
  #define BLUE_LED 2
  #define RED_PIN  27
  #define GREEN_PIN    12
  #define BLUE_PIN     13
  #define analogWrite ledcWrite
#endif

uint8_t i=0;

void setup() {
  Serial.begin(115200);
  Serial.println("\nProp-Maker Wing: LED Example");
  
  // set up the power pin
  pinMode(POWER_PIN, OUTPUT);
  // disable the power pin, we're not writing to the LEDs
  digitalWrite(POWER_PIN, LOW);

  // Set up the LED Pins
  pinMode(RED_LED, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(BLUE_LED, OUTPUT);
  #if defined(ESP32)
    ledcSetup(RED_LED, 5000, 8);
    ledcAttachPin(RED_PIN, RED_LED);
    ledcSetup(GREEN_LED, 5000, 8);
    ledcAttachPin(GREEN_PIN, GREEN_LED);
    ledcSetup(BLUE_LED, 5000, 8);
    ledcAttachPin(BLUE_PIN, BLUE_LED);
  #endif
  
  analogWrite(RED_LED, 0);
  analogWrite(GREEN_LED, 0);
  analogWrite(BLUE_LED, 0);
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return (255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return (0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return (WheelPos * 3, 255 - WheelPos * 3, 0);
}

void loop()
{
  // set RGB Colors
  uint32_t color = Wheel(i++);
  uint8_t red = color >> 16;
  uint8_t green = color >> 8;
  uint8_t blue = color;

  // turn on the power pin
  digitalWrite(POWER_PIN, HIGH);

  // write colors to the 3W LED
  analogWrite(RED_LED, red);
  analogWrite(GREEN_LED, green);
  analogWrite(BLUE_LED, blue);
  delay(100);
}

Switch

You can easily use a mechanical switch on the Switch pin with Arduino.

The following example prints to the serial monitor when the switch is closed.

/*
* Adafruit Prop-Maker Featherwing
* Switch Example
* 
* Print to the Serial Montior when a switch is pressed.
*/

#if defined(__SAMD21G18A__) || defined(__AVR_ATmega32U4__)
  #define SWITCH_PIN   9
#elif defined(__AVR_ATmega328P__)
  #define SWITCH_PIN   9
#elif defined(NRF52)
  #define SWITCH_PIN   31
#elif defined(ESP8266)
  #define SWITCH_PIN   0
#elif defined(TEENSYDUINO)
  #define SWITCH_PIN   4
#elif defined(ESP32)
  #define SWITCH_PIN   15
#endif

void setup() {
  Serial.begin(115200);
  Serial.println("\nProp-Maker Wing: Switch Example");
  // set up the switch
  pinMode(SWITCH_PIN, INPUT_PULLUP);
}

void loop()
{
  if (!digitalRead(SWITCH_PIN)) {
    Serial.println("Switch pressed!");
  }
}
This guide was first published on Jan 23, 2019. It was last updated on Jan 23, 2019. This page (Arduino Code) was last updated on Oct 21, 2019.