#include <OneSheeld.h>
boolean stopGettingReadings = false;
unsigned long lastTimeTaken = 0;
unsigned long currentTime = 0;
float x, y, z;
float lat ;
float lon ;
char charlat [30];
char charlon [30];
char readings [150];
int magnitudeThreshold = 30;
int buttonPin = 12;
void setup()
{
pinMode(buttonPin,INPUT);
OneSheeld.begin();
}
void loop()
{
charlat[0] = 0;
charlon[0] = 0;
readings [0] = 0;
if (!stopGettingReadings)
{
x = AccelerometerSensor.getX();
y = AccelerometerSensor.getY();
z = AccelerometerSensor.getZ();
}
if (sqrt((x * x) + (y * y) + (z * z)) > magnitudeThreshold)
{
stopGettingReadings = true;
Buzzer.buzzOn();
if (!lastTimeTaken)
{
lastTimeTaken = millis();
currentTime = lastTimeTaken;
}
if (currentTime - lastTimeTaken > 10000 && !digitalRead(buttonPin) == HIGH)
{
lat = GPS.getLatitude();
lon = GPS.getLongitude();
dtostrf(lat, 3, 7, charlat);
dtostrf(lon, 3, 7, charlon);
strcat(readings, "Belirtilen Konumda Trafik Kazasi Yaptim!:\n");
strcat(readings, "Yardima Ihtiyacim var.\n");
strcat(readings, "http://maps.google.com/maps?q=");
strcat (readings, charlat);
strcat(readings, ",");
strcat (readings, charlon);
SMS.send("11111111111", readings);
Camera.rearCapture();
OneSheeld.delay(1000);
Email.send("adsoyad@servis.com", "Guvenlik Mesaji", readings);
OneSheeld.delay(10000);
Email.attachLastPicture("adsoyad@servis.com", "Guvenlik Mesaji", "Trafik Kazasi Bildirimi");
OneSheeld.delay(1000);
resetSystem();
}
else
{
if (digitalRead(buttonPin) == HIGH)
{
resetSystem();
Terminal.println("Bildirim Iptal Edildi.");
}
else currentTime = millis();
}
}
}
void resetSystem()
{
Buzzer.buzzOff();
stopGettingReadings = false;
lastTimeTaken = 0;
currentTime = 0;
}