CJA3D
Published © CC BY-NC

Rocket's Command Center 

Add life to any old poster at home using a Spark Core, Neo-pixels and piezo buzzer

IntermediateFull instructions provided1,042
Rocket's Command Center 

Things used in this project

Hardware components

Spark Core
Particle Spark Core
×1
Adafruit NeoPixel
×1
Adafruit Piezo Buzzer
×1

Story

Read more

Code

Rocket_Command_center_SparkCore_Code.txt

C/C++
//Author: Carmelito Andrade,License: Creative Commons License CC BY-SA 3.0
// This #include statement was automatically added by the Spark IDE.
#include "neopixel/neopixel.h"
// name the pins
int led1 = D4;
int led2 = D1;

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D3
#define PIXEL_COUNT 5
#define PIXEL_TYPE WS2811
#define PiezoPin D0

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

// This routine runs only once upon reset
void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
   //Register our Spark function here
   Spark.function("rocket", rocketControl);

   pinMode(PiezoPin, OUTPUT);    
   Serial.begin(9600);
   Serial.println("in setup");
   delay(5000);
   beeps();//beep to indcate that rocket has powered on

}


// This routine loops forever
void loop()
{
   //Un-Comment for Testing Neo-pixel connection after soldering the Neo-Pizel
    /*uint16_t i;
    for(i=0; i<strip.numPixels(); i++) {
     strip.setPixelColor(i, strip.Color(0, 255, 0)); //green
    }
    strip.show();  */


}



void beeps() {
 tone(PiezoPin,625,125);
  delay(250);
 
  tone(PiezoPin,445,125);
  delay(250);
}


int rocketControl(String command)
{
   int state = 0;

   if(command == "WARN1") //Warning 1
   {
       state = 1;
     uint16_t i;
    for(i=0; i<strip.numPixels(); i++) {
     strip.setPixelColor(i, strip.Color(255, 255, 0)); //yellow
    delay(500);
    strip.show();  
    }
    beeps();

   }
   
   else if(command == "WARN2")  //sencond warning from the webpage 
   {
       state = 0;
     uint16_t i;
    for(i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, strip.Color(0, 255, 0)); //all Red
    delay(500);
    strip.show(); 
    }
    beeps();
   delay(1000);
   beeps();
  
   }
     else if(command == "WARN3")  //.substring(3,6) 
   {
       state = 0;
     uint16_t i,j,k;
    for(i=0; i<strip.numPixels() -3; i++) {
    strip.setPixelColor(i, strip.Color(0, 255, 0)); //Red
    delay(500);
    strip.show(); 
    beeps();
    }
   for(j=0; j<256; j++) {
    for(k=strip.numPixels() -3; k<strip.numPixels(); k++) {
      strip.setPixelColor(k, Wheel((j+k) & 255));
    }
    beeps();
    strip.show();
  }
  
   }
      else if(command == "RESET")  //Reset all pixels to blank
   {
       state = 0;
     uint16_t i;
    for(i=0; i<strip.numPixels(); i++) {
     strip.setPixelColor(i, strip.Color(0, 0, 0)); //reset all the pixels to off mode
    }
    strip.show(); 
    
       
   }
   else return -1;
      
   
   return 1;
}

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

Credits

CJA3D

CJA3D

10 projects • 78 followers
Tinkerer and 3D Printing enthusiast.

Comments

Add projectSign up / Login