Back to Parent

int i = 0;
int irpin = A0;
int irval = 0;
int len = 700;
int empin = D0;
int set = 0;

int ComingHandler(const char *event, const char *data)
{
    len = 450;
    set = 1;
    return 1;
}

int GoingHandler(const char *event, const char *data)
{
    len = 700;
    set = 0;
    return 1;
}


void setup()
{
   // set  the transistor pin as output:
   pinMode(empin, OUTPUT);
   Particle.variable("reading", &irval, INT);
   pinMode(irpin, INPUT);
   Particle.subscribe("comingback", ComingHandler);
   Particle.subscribe("goingaway", GoingHandler);
   Particle.variable("interval", &len, INT);
}

void loop()
{
   if(set)
   {
     irval = 10000/analogRead(irpin);
     if(irval<10)
     {
       len =200;
     }
     else
     {
       len = 450;
     }
   }

   //analogWrite(empin, 120);
   //delay(len/4);
   analogWrite(empin, 255);
   delay(len/4);
   analogWrite(empin, 0);
   delay(len/4);

   //analogWrite(empin, 120);
   //delay(len/4);
   analogWrite(empin, 255);
   delay(len/4);
   analogWrite(empin, 0);
   delay(len);
 }
Click to Expand

Content Rating

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

0