Created
August 11, 2016 23:36
-
-
Save michaelhohl/ef78b4ed7e626c359bfcb5a9968be43a to your computer and use it in GitHub Desktop.
This file contains 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
#include "application.h" | |
bool bikeIsOn = false; | |
int inputPin[6] = {A0,A1,A2,A3,A4,A5}; | |
int bikeValue[6]; | |
int bikePreviousValue[6]; | |
int i = 0; | |
char publishString[40]; | |
void setup() { | |
Serial.begin(9600); | |
Time.zone(-7); | |
//setup input pins | |
for (i = 0; i <= 5; i++) { | |
pinMode(inputPin[i], INPUT); | |
bikePreviousValue[i] = analogRead(inputPin[i]); | |
} | |
Serial.println("booted"); | |
} | |
void loop() { | |
//do this 6 times | |
for (i = 0; i <= 5; i++) { | |
bikeValue[i] = analogRead(inputPin[i]); | |
Serial.print("Bike: "); | |
Serial.print(i); | |
Serial.print("Value: "); | |
Serial.println(bikeValue[i]); | |
sprintf(publishString,"RackSlot %d", i); | |
if ((bikeValue[i] - bikePreviousValue[i]) > 600 && bikeIsOn == false) { | |
bikeIsOn = true; | |
if (Time.isAM()) { | |
Particle.publish("Bike On", publishString); | |
Serial.println("bike is on"); | |
} | |
//publish Particle event ON | |
} | |
if ((bikePreviousValue[i] - bikeValue[i]) > 600 && bikeIsOn == true) { | |
bikeIsOn = false; | |
//Serial.println("bike is off"); | |
//Particle.publish("Bike Off", publishString); | |
} | |
bikePreviousValue[i] = bikeValue[i]; | |
} | |
delay(3000); | |
Serial.println(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment