Back to Parent

Final Code
Servo legs;
int servoPin = A4;
int servoPos = 0;
unsigned long lastPulledTime2=60000;
int pokeState = 0;
int solPin2 = D5;
int pokePin2 = A1;
void setup()
{
  legs.attach(A4);
  Particle.subscribe("hairpulledAmmani", kick );
  Particle.subscribe("pokedAmmani", start_biting_Am);
  pinMode(solPin2, OUTPUT);
  pinMode(pokePin2, INPUT);
}
void loop()
{
  hairpulled2();
  poked();
}
void kick(const char *event, const char *data)
{
  for (int i=0; i <3; i++)
    {
      legs.write (160);
      delay(500);
      legs.write(20);
      delay(600);
    }
}
int start_biting_Am(const char *event, const char *data)
{
  for( int i = 0; i < 5; i++ )
   {
    digitalWrite(solPin2, HIGH);
    delay( 50 ) ;
    digitalWrite(solPin2, LOW);
    delay( 50 );
   }
}
void hairpulled2()
{
  if (millis()-lastPulledTime2 > 10000)
    {
      if (digitalRead(D4) == LOW )
      {
        Particle.publish("hairpulledSurabhi");
        lastPulledTime2 = millis();
      }
  }
}
void poked()
{
  pokeState = analogRead(pokePin2);
  if (pokeState >= 1000)  //if pokeState is low- in case of an FSR, it means I have been poked
  {
    Particle.publish("pokedSurabhi");
  }
}
Click to Expand

Content Rating

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

0