Back to Parent

int blue = D0;
int green = D1;
int red = D2;
int xServoPin = D3;
int yServoPin = A4;
Servo shakeitoff;
Servo pullitup;
int angle = 0;   // servo position in degrees
void setup() {
  pinMode(red, OUTPUT);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
  shakeitoff.attach(xServoPin);
  pullitup.attach(yServoPin);
  Particle.subscribe("politics", anger, MY_DEVICES);
  Particle.subscribe("travel", growth, MY_DEVICES);
  Particle.subscribe("food_and_wine", sated, MY_DEVICES);
  Particle.subscribe("technology", pensive, MY_DEVICES);
}
void loop()
{
digitalWrite(blue, HIGH);
digitalWrite(green, HIGH);
digitalWrite(red, HIGH);
}
void anger (const char *event, const char *data)
{
digitalWrite(green, HIGH);
  for (int x= 0; x < 5; x++){
    digitalWrite(red,LOW);
    //delay(300);
    // scan from 0 to 180 degrees
    for(angle = 10; angle < 45; angle++){
      shakeitoff.write(angle);
      delay(3);
    }
    delay(50);
    digitalWrite(red, HIGH);
    //delay(300);
    // now scan back from 180 to 0 degrees
    for(angle = 45; angle > 10; angle--){
      shakeitoff.write(angle);
      delay(3);
    }
    delay(50);
  }
}
void growth(const char *event, const char *data)
{
  for(int angle = 0; angle < 90; angle++)
  {
    pullitup.write(angle);
    delay(15);
  }
  for (int x= 0; x < 5; x++){
    for (int i= 255; i>0; i--)
    {
      analogWrite (green,i);
      delay(5);
    }
    //delay(500);
    for (int i = 0; i<=255; i++)
    {
      analogWrite (green,i);
      delay(5);
    }}
    //delay(500);
  for(int angle = 90; angle > 0; angle--)
  {
    pullitup.write(angle);
    delay(15);
  }
}
void sated(const char *event, const char *data)
{
  for (int x= 0; x<3; x++){
    for(int n = 0; n <255 ; n++){
      analogWrite(green, 255-0.57*n);
      analogWrite(red,255-n);
      delay(5);
      }
    for(int n= 0; n<255; n++){
      analogWrite(green, 108+0.57*n);
      analogWrite(red,n);
      delay(5);
      }
    }
}
    // scan from 0 to 180 degrees
    /*for(angle = 10; angle < 55; angle++)
    {
      shakeitoff.write(angle);
      delay(45);
    }
    delay(300);
    // now scan back from 180 to 0 degrees
    for(angle = 55; angle > 10; angle--)
    {
      shakeitoff.write(angle);
      delay(45);
    }
    delay(300);
  }
}*/
void pensive (const char *event, const char *data)
{
/*  for (int x= 0; x<3; x++){
    //analogWrite(green,108);
    analogWrite(blue,0);
    // scan from 0 to 180 degrees
    for(angle = 10; angle < 55; angle++)
    {
      shakeitoff.write(angle);
      delay(45);
    }
    delay(300);
    // now scan back from 180 to 0 degrees
    for(angle = 55; angle > 10; angle--)
    {
      shakeitoff.write(angle);
      delay(45);
    }
    delay(300);
  }
}
*/
    for (int x= 0; x<3; x++){
      //analogWrite(green,108);
      analogWrite(blue,0);
      // scan from 0 to 180 degrees
      for(angle = 10; angle < 170; angle++)
      {
        shakeitoff.write(angle);
        delay(15);
      }
      //delay(150);
      // now scan back from 180 to 0 degrees
      for(angle = 170; angle > 10; angle--)
      {
        shakeitoff.write(angle);
        delay(15);
      }
      //delay(150);
    }
  }
Add Comment Collapse
Click to Expand

Content Rating

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

0