Back to Parent

// This is the code for the activity indicator
#include <Adafruit_PWMServoDriver.h>

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

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


int servoPin = A3;
Servo myServo;
int servoPos = 0;
void setup() {
    // attaches the servo on the A3 pin to the servo object
    myServo.attach( A3 );

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

     // Basically this will match any event that starts with 'db2018/paired/'
     // This is a feature we'll useto figure out if our event comes from
     // this device or another (see publishMyEvent below)
     Particle.subscribe(  "sixkids/2019/paired/" , sixKidsPublish);
     Particle.subscribe(  "threekids/2019/paired/" , threeKidsPublish );
     Particle.subscribe(  "tenkids/2019/paired/" , tenKidsPublish );
}

// Our event handlde requires two bits of information
// This gives us:
// A character array that consists of the event name
// A character array that contains the data published in the event we're responding to.
void threeKidsPublish(const char *event, const char *data)
{
    int newPoz = 40;
    
    servoPos = constrain (newPoz, 0, 180);
    
      // Set the servo
   myServo.write( servoPos );
   
   delay(10000);
   servoPos = constrain (20, 0, 180);
   


}

void sixKidsPublish(const char *event, const char *data)
{
    int newPoz = 105;
    
    servoPos = constrain (newPoz, 0, 180);
    
      // Set the servo
   myServo.write( servoPos );


}

void tenKidsPublish(const char *event, const char *data)
{
    int newPoz = 160;
    
    servoPos = constrain (newPoz, 0, 180);
    
      // Set the servo
   myServo.write( servoPos );


}
Click to Expand

Content Rating

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

0