int solPin = D2;
bool shouldActivate = false;
void setup()
{
pinMode(solPin, OUTPUT);
Particle.function( "activate", activateSolenoid );
}
void loop()
{
if( shouldActivate ){
doSolenoid( );
shouldActivate = false;
}
delay( 100 );
}
void doSolenoid( ){
for( int i = 0; i < 5; i++ )
{
digitalWrite(solPin, HIGH);
delay( 100 ) ;
digitalWrite(solPin, LOW);
delay( 100 );
}
}
int activateSolenoid( String command ){
shouldActivate = true;
return 1;
}
Click to Expand