Back to Parent

#include <neopixel.h>

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D0
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

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

int servoPin = A5;
Servo myServo;
int servoPos = 0;
int pos = 0;
int count = 9000;
int ledPin = D1;

void setup() {


  // attaches the servo on the A5 pin to the servo object
  myServo.attach( A5 );

   //Register our Particle to control the servo
  Particle.function("servo", servoControl);

  // Keep a cloud variable for the current position
  Particle.variable(  "servoPos" , &servoPos , INT );

  Particle.subscribe("catdeath", catswing);

  strip.begin();
  strip.show();

}


void loop(){

/*if (servoPos == 15 )
  {
    catswing();

  }

}*/

void catswing (*const char *event, const char *data){
    pos = 78;
    //servoPos = 16;



    for(int i=0; i<65; i++)
    {
      uint32_t j;
       for(j=0; j< strip.numPixels(); j++)
       strip.setPixelColor(j, 255, 255, 255 );e
       strip.show();

      myServo.write(pos);
      delay(1000);
      pos++;



    }
    uint32_t k;
     for(k=0; k< strip.numPixels(); k++)
     strip.setPixelColor(k, 255, 0, 0 );
     strip.show();
    delay (5000);

    myServo.write( 78 );

    uint32_t l;
     for(l=0; l< strip.numPixels(); l++)
     strip.setPixelColor(l, 0, 0, 0 );
     strip.show();

    // return 1;
}


int servoControl( String command )
{
   servoPos = command.toInt();
   // Make sure it is in the right range
   // And set the position


   // Set the servo


   // done
   return 1;
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0