Skip to content

Instantly share code, notes, and snippets.

@technobly
Last active December 15, 2015 14:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technobly/177edb14c10ad89b7eca to your computer and use it in GitHub Desktop.
Save technobly/177edb14c10ad89b7eca to your computer and use it in GitHub Desktop.
Particle Internet Button Police Lights
// 1. CREATE A NEW APP at https://build.particle.io
// 2. PASTE THIS CODE IN and SAVE
// 3. GO TO LIBRARIES, OPEN the NEOPIXEL library
// 4. Click INLUCDE IN APP
// 5. SELECT THE APP YOU PASTED/SAVED THIS CODE IN
// 6. Click ADD TO THIS APP
// 7. COMPILE and FLASH to a PARTICLE INTERNET BUTTON
// 8. SHINE IT DOWN ON SOMETHING AND BE AMAZED :)
// 9. WOOP WOOP!!, THAT'S THE SOUND OF THE POLICE!
//
// This #include statement was automatically added by the Particle IDE.
#include "neopixel/neopixel.h"
//----------------- LED Handling ------------------------
#define PIXEL_COUNT 11
#define PIXEL_PIN D3
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel ring = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void allLedsOn(uint8_t r, uint8_t g, uint8_t b){
for(int i = 0; i<PIXEL_COUNT; i++){
ring.setPixelColor(i, ring.Color(r, g, b));
}
ring.show();
}
void setup() {
Serial.begin(9600);
ring.begin();
ring.setPixelColor(0, ring.Color(0, 100, 255));
ring.setPixelColor(0, ring.Color(255, 0, 0));
//ring.setBrightness(10);
ring.show();
delay(40);
}
void loop() {
static uint8_t head = 1;
static uint8_t tail = 0;
static uint8_t head2 = 7;
static uint8_t tail2 = 6;
static int bright = 255;
static bool dir = 0;
static char output[255];
static uint32_t newcolor;
static uint32_t oldcolor;
oldcolor = ring.getPixelColor(tail);
uint8_t r = (uint8_t)(oldcolor >> 16);
uint8_t g = (uint8_t)(oldcolor >> 8);
uint8_t b = (uint8_t)oldcolor;
ring.setPixelColor(head, ring.Color(0, 100, 255));
ring.setPixelColor(tail, ring.Color(0, 0, 0));
ring.setPixelColor(head2, ring.Color(255, 0, 0));
ring.setPixelColor(tail2, ring.Color(0, 0, 0));
newcolor = ring.getPixelColor(head);
uint8_t r1 = (uint8_t)(newcolor >> 16);
uint8_t g1 = (uint8_t)(newcolor >> 8);
uint8_t b1 = (uint8_t)newcolor;
/*
sprintf(output, "Set Color: %3d %3d %3d - Get Color: %3d %3d %3d - Bright: %d", r, g, b, r1, g1, b1, ring.getBrightness());
Serial.println(output);
if (dir == 0) {
ring.setBrightness(bright--);
if (bright == 0) {
dir = 1;
}
}
else {
ring.setBrightness(bright++);
if (bright == 255) {
dir = 0;
}
}
*/
ring.show();
if(++head == 11) head = 0;
if(++tail == 11) tail = 0;
if(++head2 == 11) head2 = 0;
if(++tail2 == 11) tail2 = 0;
delay(40);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment