int solPin = D2;
bool shouldActivate = false;
void setup()
{
Particle.function( "activate", activateSolenoid );
Particle.function( "speed", setSpeed);
pinMode(solPin, OUTPUT);
}
void loop()
{
if( shouldActivate ){
doSolenoid( );
shouldActivate = false;
}
delay( 100 );
}
void doSolenoid( ){
digitalWrite(solPin, HIGH);
for( int i = 0; i < 5; i++ )
{
digitalWrite(solPin, HIGH);
delay( 1000 ) ;
digitalWrite(solPin, LOW);
delay( 1000 );
}
}
int activateSolenoid( String command ){
shouldActivate = true;
return 1;
}
int setSpeed( String command){
int speed = command.toInt();
analogWrite(solPin, speed);
return 1;
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .