Back to Parent

int VibratePin = D2;
//bool shouldActivate = false;
int level =0;
void setup()
{
  //Particle.function( "Teddyvibrate", Teddyvibrate );
  Particle.subscribe("diot/2019/paired/guardianteddy/vibrate", Vibrate);
  Particle.publish("Start");
  pinMode(VibratePin, OUTPUT);
  delay(3000);
}
void loop()
{
  //Particle.publish("Pulse");
  //delay(3000);
  vibratelevel(1);
  delay(3000);
}
void Vibrate(const char *event, const char *data)
{
    /*
    if (data=="2");
    {
        Particle.publish("It worked!", data);
        vibratelevel(2);
    }
    */
    Particle.publish("It worked!", data);
    delay(3000);
    if(data=="1")
    {
    vibratelevel(1);
    }
    else if (data=="2")
    {
    vibratelevel(2);
    }
    else{
    vibratelevel(0);
    }
}
void vibratelevel(int level)
{
    if(level = 0)
        return;
        for(int i = 0; i < 3 * level; i++)
        {
            digitalWrite(VibratePin, HIGH);
            delay(100 * level);
            digitalWrite(VibratePin, LOW);
            delay(500 / level);
        }
}
Click to Expand

Content Rating

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

0