int solPin = D3;
bool shouldActivate = false;
int ledPin = D7;
void setup() {
Particle.function("activate", activateSolenoid);
pinMode(solPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (shouldActivate) {
Particle.publish("activated");
doSolenoid();
shouldActivate = false;
}
delay(100);
}
void doSolenoid() {
for (int i = 0; i < 10; i++) { // Activate the solenoid 10 times
digitalWrite(solPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(solPin, LOW);
digitalWrite(ledPin, LOW);
delay(100);
}
}
int activateSolenoid(String command) {
if (command == "instock") { // Check if instock
shouldActivate = true;
return 1;
}
return 0; // Return 0 if not instock
}
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. .