Other considerations: I'm using this with the 8 LED NeoPixel stick. I also have the nrf8001 stacked on the Trinket Pro using double-sided tape. Is that likely to mess up communication? I stacked it on the back behind the components area, the antenna area of the nrf board is uncovered by anything.
Here's my program, I have a simple lighting effect and wanted to change the color of the Neopixels if a character came in over BLE.
Code: Select all
#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include "Adafruit_BLE_UART.h"
// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_REQ 6
#define ADAFRUITBLE_RDY 3 // This should be an interrupt pin, on Uno thats #2 or #3
#define ADAFRUITBLE_RST 8
#define PIN 9
Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
const uint8_t maxBrightness = 100;
uint32_t color;
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
BTLEserial.begin();
strip.begin();
strip.show(); // Initialize all pixels to 'off'
color = strip.Color(100, 30, 255);
}
aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;
void loop() {
aci_evt_opcode_t status = BTLEserial.getState();
if (status == ACI_EVT_CONNECTED) {
// Lets see if there's any data for us!
while (BTLEserial.available()) {
char c = BTLEserial.read();
switch (c) {
case 'r':
color = strip.Color(255, 0, 0);
break;
case 'g':
color = strip.Color(0, 255, 0);
break;
case 'b':
color = strip.Color(0, 0, 255);
break;
case 'o':
color = strip.Color(0, 0, 0);
break;
}
}
}
strip.setBrightness(maxBrightness);
centerOut(color);
delay(200);
centerOutOff();
delay(200);
}
void centerOut(uint32_t c) {
strip.setPixelColor(3, c);
strip.setPixelColor(4, c);
strip.show();
delay(200);
strip.setPixelColor(2, c);
strip.setPixelColor(5, c);
strip.show();
delay(200);
strip.setPixelColor(1, c);
strip.setPixelColor(6, c);
strip.show();
delay(200);
strip.setPixelColor(0, c);
strip.setPixelColor(7, c);
strip.show();
}
void centerOutOff() {
strip.setPixelColor(3, strip.Color(0,0,0));
strip.setPixelColor(4, strip.Color(0,0,0));
strip.show();
delay(200);
strip.setPixelColor(2, strip.Color(0,0,0));
strip.setPixelColor(5, strip.Color(0,0,0));
strip.show();
delay(200);
strip.setPixelColor(1, strip.Color(0,0,0));
strip.setPixelColor(6, strip.Color(0,0,0));
strip.show();
delay(200);
strip.setPixelColor(0, strip.Color(0,0,0));
strip.setPixelColor(7, strip.Color(0,0,0));
strip.show();
}