Make sure your Photon is plugged into your computer and sign into Particle.io. Then, go into "Console" and make sure you've selected your Photon device. Next, go into the "IDE" and enter the code below. It's important to load the code before you get to the next step of "Finishing Touches" as a function is called that needs to be read by the program IFTTT (IfThisThenThat). 

Make sure you have added the Adafruit NeoPixel Library in Particle Build for this sketch to work. Just because the code lists the library doesn't mean that it is seen. It will generate its own line of code.
Download: file
/* ISS Pin by Leslie Birch for Adafruit Industries
Based on NeoPixel Library by Adafruit and code from Particle.io
This version connects with IFTTT and shows a ring of blue, white, red and multi when triggered. 
When not triggered, it does a comet chase of white. */

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

#include "application.h"

SYSTEM_MODE(AUTOMATIC);

void colorWipe(uint32_t c, uint8_t wait);

#define PIXEL_PIN D6
#define PIXEL_TYPE WS2812B

const int FADE_LENGTH = 3;
const int FADE_SCALE  = 128;
const int PIXEL_COUNT = 24;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

bool toggle = false;

int pos = 0, dir = 1; 
int j;

int pixelToggle(String command);

void setup(){
  strip.begin();
  strip.setBrightness(70); //set the brightness of NeoPixels to your preference
  strip.show(); // Initialize all pixels to 'off'
  
    Particle.function("pixelPIN", pixelToggle);
}
  void loop (){

   if(toggle==true){
   
  colorWipe(strip.Color(0, 0, 255), 25); // Blue
  colorWipe(strip.Color(0, 0, 255), 25); // Blue
  colorWipe(strip.Color(150, 150, 150), 25); // White
  colorWipe(strip.Color(150, 150, 150), 25); // White
  colorWipe(strip.Color(255, 0, 0), 25); // Red
  colorWipe(strip.Color(255, 0, 0), 25); // Red
  strip.setPixelColor(0,0,0,255);
  strip.setPixelColor(3,0,0,255);
  strip.setPixelColor(6,0,0,255);
  strip.setPixelColor(9,0,0,255);
  strip.setPixelColor(12,0,0,255);
  strip.setPixelColor(15,0,0,255);
  strip.setPixelColor(18,0,0,255);
  strip.setPixelColor(21,0,0,255);
  strip.setPixelColor(1,150,150,150);
  strip.setPixelColor(4,150,150,150);
  strip.setPixelColor(7,150,150,150);
  strip.setPixelColor(10,150,150,150);
  strip.setPixelColor(13,150,150,150);
  strip.setPixelColor(16,150,150,150);
  strip.setPixelColor(19,150,150,150);
  strip.setPixelColor(22,150,150,150);
  strip.setPixelColor(2,255, 0, 0),
  strip.setPixelColor(5,255, 0, 0),
  strip.setPixelColor(8,255, 0, 0),
  strip.setPixelColor(11,255, 0, 0),
  strip.setPixelColor(14,255, 0, 0),
  strip.setPixelColor(17,255, 0, 0),
  strip.setPixelColor(20,255, 0, 0),
  strip.setPixelColor(23,255, 0, 0),
  strip.show();
  delay(5000);
  colorWipe(strip.Color(0, 0, 0), 0); // off
  (toggle = false);
   }

    else {
     
    comet();
    }
  }
   
   void comet (){
        for ( int i=0 ; i < PIXEL_COUNT * 5 ; i++ ) {
        for ( int p=0 ; p < PIXEL_COUNT ; p++ ) {
            strip.setPixelColor( p, 0 );  //  clear the strip
        }
        drawFade( i, 255, 255, 149);        //  then draw the fade
        strip.show();
        delay( 400 );
    }
}

void drawFade ( uint8_t start, uint8_t r, uint8_t g, uint8_t b ) {
    int brightness = 50;
    for ( int p=0 ; p < FADE_LENGTH ; p++ ) {
        strip.setPixelColor( 
            ( start - p ) % PIXEL_COUNT, 
            strip.Color( 
                ( r * brightness ) / 255,
                ( g * brightness ) / 255,
                ( b * brightness ) / 255                
            )
        );
        brightness = ( brightness * FADE_SCALE ) / 255;
    }
} void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(50);
  }
}

int pixelToggle(String command){
    toggle = true;
}

This guide was first published on Apr 17, 2017. It was last updated on Apr 17, 2017.

This page (Code) was last updated on Mar 05, 2021.

Text editor powered by tinymce.