This commit is contained in:
James Devine 2015-07-17 08:16:02 -07:00
parent 3a439aeac1
commit d0408d5f9b

36
piread
View file

@ -1,3 +1,4 @@
#include <Adafruit_GPS.h> #include <Adafruit_GPS.h>
#include <Adafruit_Sensor.h> #include <Adafruit_Sensor.h>
#include <Adafruit_L3GD20_U.h> #include <Adafruit_L3GD20_U.h>
@ -8,6 +9,7 @@
#include <Wire.h> #include <Wire.h>
#define mySerial Serial1 #define mySerial Serial1
#define GPSECHO true #define GPSECHO true
const int timeresetpin = 50;
Adafruit_10DOF dof = Adafruit_10DOF(); Adafruit_10DOF dof = Adafruit_10DOF();
@ -21,6 +23,7 @@ char gpstext[ ] = "";
String gpstalk; String gpstalk;
String inputString = ""; // a string to hold incoming data String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete boolean stringComplete = false; // whether the string is complete
boolean eventhappened = false; //has an event been detected?
String lastgpsread; String lastgpsread;
int energy1 = random(10000, 20000); int energy1 = random(10000, 20000);
int energy2 = random(10050, 19950); int energy2 = random(10050, 19950);
@ -36,7 +39,7 @@ double magx = 0;
double magy = 0; double magy = 0;
double magz = 0; double magz = 0;
int timereset = 0;
int exacttime =0; int exacttime =0;
int uptime = 0; int uptime = 0;
@ -64,11 +67,15 @@ void setup()
delay(1000); delay(1000);
Serial.println("GPS online"); Serial.println("GPS online");
inputString.reserve(200); inputString.reserve(200);
pinMode(timeresetpin, INPUT);
attachInterrupt(50, beep, RISING);
} }
void loop() // run over and over again void loop() // run over and over again
{ {
exacttime++;
if (stringComplete) { if (stringComplete) {
lastgpsread = inputString; lastgpsread = inputString;
lastgpsread.trim(); lastgpsread.trim();
@ -78,10 +85,28 @@ void loop() // run over and over again
stringComplete = false; stringComplete = false;
} }
if (eventhappened) {
Serial.println("Beep");
eventhappened = false;
sensorreadout(); sensorreadout();
printdatajson(); printdatajson();
delay(100); exacttime = 0;
}
// timereset = digitalRead(timeresetpin);
// exacttime++;
// if (timereset != digitalRead(timeresetpin))
// {
// if (digitalRead(timeresetpin) == HIGH )
// {
// exacttime = 0;
// }
// }
// }
//delay(100);
} }
void printdatajson() void printdatajson()
@ -243,11 +268,14 @@ void sensorreadout()
humidity = (htu.readHumidity()); humidity = (htu.readHumidity());
} }
exacttime++;
energy1= energy1 + random(-100,100); energy1= energy1 + random(-100,100);
energy2= energy2 + random(-100,100); energy2= energy2 + random(-100,100);
uptime++; uptime++;
} }
void beep()
{
eventhappened = true;
}