Skip to content

Instantly share code, notes, and snippets.

@mrvanbakel
Last active July 28, 2016 20:07
Show Gist options
  • Save mrvanbakel/df5049969bc04e58d16a to your computer and use it in GitHub Desktop.
Save mrvanbakel/df5049969bc04e58d16a to your computer and use it in GitHub Desktop.
Particle Photon - Like button + IFTTT tweets every so many likes.
int pushes = 0;
int frequency = 10;
int button = LOW;
int buttonPin = D0;
int ledPin = D7;
void setup() {
pinMode(buttonPin,INPUT);
pinMode(ledPin,OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH); // Turn LED on - for feedback
button = digitalRead(buttonPin); // Read if button is pushed
if (button == HIGH){ // if the button has been pushed
pushes++; // Add +1 to the number of pushes
digitalWrite(ledPin, LOW); // Turn the LED off, to indicate button works
if (pushes % frequency == 0){ // Every 10, 20, 30, 40 etc
Spark.publish("publish",String(pushes)); // publish the number of pushes to IFTTT
}
delay(400); // delay before turning LED back on (and prevent spam)
button = LOW;
}
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment