Created
February 26, 2016 17:17
-
-
Save mlapida/579affd5395b8cc74eb9 to your computer and use it in GitHub Desktop.
A small Particle firmware for sending movement data to a web-hook.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Make sure to include the spcial library for the internet button | |
#include "InternetButton/InternetButton.h" | |
// Create a Button named b. It will be your friend, and you two will spend lots of time together. | |
InternetButton b = InternetButton(); | |
int ledOldPos = 0; | |
char ledPosTrust[5]; | |
int moveCount = 0; | |
int loopCount =0; | |
// The code in setup() runs once when the device is powered on or reset. Used for setting up states, modes, etc | |
void setup() { | |
// Tell b to get everything ready to go | |
// Use b.begin(1); if you have the original SparkButton, which does not have a buzzer or a plastic enclosure | |
// to use, just add a '1' between the parentheses in the code below. | |
b.begin(); | |
} | |
/* loop(), in contrast to setup(), runs all the time. Over and over again. | |
Remember this particularly if there are things you DON'T want to run a lot. Like Spark.publish() */ | |
void loop() { | |
// Load up the special "lowestLed" object | |
int ledPos = b.lowestLed(); | |
// Turn the LEDs off so they don't all end up on | |
b.allLedsOff(); | |
// I'm movin', incriment the counter up | |
if (ledOldPos != ledPos){ | |
sprintf(ledPosTrust,"%d",ledPos); | |
moveCount++; | |
} | |
//The button's have been triggered! Record this! | |
if ((b.buttonOn(2) and b.buttonOn(4)) or (b.buttonOn(1) and b.buttonOn(3))) { | |
b.ledOn(3, 0, 255, 0); // Green | |
b.ledOn(9, 0, 255, 0); // Green | |
Particle.publish("sendSleep", "True", 60, PRIVATE); | |
delay(500); | |
} | |
// if we've looped through x times, fire off the webhook | |
if (loopCount >= 600){ | |
Particle.publish("sendSleep", String(moveCount), 60, PRIVATE); | |
moveCount = 0; | |
loopCount = 0; | |
} | |
loopCount++; | |
ledOldPos = ledPos; | |
// Wait a mo' | |
delay(100); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment