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