Back to Parent

int solPin = D2;
int buttonPin = D3;
bool shouldActivate = false;

void setup() {

    pinMode( solPin, OUTPUT);
    pinMode( buttonPin, INPUT_PULLUP);

    Particle.subscribe( "activate", activateSolenoid );
    // blinkLED( 3, ledPin );

}

void loop() {

    int buttonValue = digitalRead( buttonPin );
    if( buttonValue == LOW ){
        Particle.publish( "doPairedPublish" );
    }

    if( shouldActivate == true ){
       doSolenoid(  );
       shouldActivate = false;
    }

    delay( 1000 );

}

void activateSolenoid( const char *event, const char *data)
{
   shouldActivate = true;
}

void doSolenoid(  ){
  for( int i = 0; i < 5; i++ )
  {
    digitalWrite(solPin, HIGH);
    delay( 2000 ) ;
    digitalWrite(solPin, LOW);
    delay( 1000 );
  }
}
Click to Expand

Content Rating

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

0