Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MODSERIAL ADXL345 MODGPS
main.cpp
00001 #include "mbed.h" 00002 #include "stdio.h" 00003 #include "sms.h" //custom sms library 00004 #include "SecurityMechanism.h" //custom security mechanism library 00005 #include "MODSERIAL.h" //buffer library for serial 00006 #include "GPS.h" //GPS library 00007 #include "ADXL345.h" //Sparkfun ADXL345 accelerometer library 00008 00009 // System 00010 DigitalOut pulse(LED1); //heartbeat 00011 Serial pc(USBTX,USBRX); //for debugging 00012 00013 // Peripherals 00014 MODSERIAL gsm(p28,p27); 00015 GPS gps(NC, p10); 00016 ADXL345 accelerometer(p5, p6, p7, p8); 00017 00018 // Power Control 00019 DigitalOut gps_on(p22); 00020 DigitalOut gps_xstandby(p21); 00021 DigitalOut accelerometer_on(p20); 00022 //DigitalIn security_pwrd(p17); 00023 AnalogIn voltage_level(p19); 00024 00025 // Global Vars 00026 int accel_reading[3] = {0, 0, 0}; //x, y, z coordinates of accelerometer 00027 int prev_accel_reading[3] = {0, 0, 0}; //x, y, z coordinates of accelerometer 00028 string phoneNumber = "4047849578"; 00029 bool security_enabled = true; 00030 bool movement_detected = false; 00031 bool command_sent = false; 00032 #define ACCEL_THRESH 50 00033 00034 int main() { 00035 pc.printf("Initializing Program.\r\n"); 00036 //****init GSM 00037 GSM_init(); 00038 00039 //****init GPS 00040 pc.printf("Initializing GPS.\r\n"); 00041 GPS_Time t; 00042 gps.baud(4800); 00043 00044 //****init accelerometer 00045 accelerometer_on = 1; 00046 pc.printf("Initializing Accelerometer.\r\n"); 00047 //Go into standby mode to configure the device. 00048 accelerometer.setPowerControl(0x00); 00049 00050 //Full resolution, +/-16g, 4mg/LSB. 00051 accelerometer.setDataFormatControl(0x0B); 00052 00053 //3.2kHz data rate. 00054 accelerometer.setDataRate(ADXL345_3200HZ); 00055 00056 //Measurement mode. 00057 accelerometer.setPowerControl(0x08); 00058 00059 pc.printf("Initializing Complete.\r\n"); 00060 00061 wait(0.4); 00062 00063 while(1) { 00064 accelerometer.getOutput(accel_reading); 00065 //check for movement 00066 for (int i = 0; i < 3; i++) { 00067 if (((int16_t)prev_accel_reading[i] != 0) && (int16_t)abs(accel_reading[i] - prev_accel_reading[i]) > ACCEL_THRESH) { 00068 pc.printf("Movement detected\r\n"); 00069 movement_detected = true; 00070 } 00071 prev_accel_reading[i] = accel_reading[i]; 00072 } 00073 00074 //pc.printf("Seurity system = %d\r\n", security_pwrd); 00075 //security_enabled = security_pwrd; 00076 00077 if (movement_detected) { 00078 if (security_enabled) { 00079 //turn off accelerometer 00080 accelerometer_on = 0; 00081 pc.printf("Alert\r\n"); 00082 send_location(); 00083 wait(30); 00084 } 00085 } 00086 00087 if (command_sent) { 00088 pc.printf("Ping.\r\n"); 00089 send_location(); 00090 command_sent = false; 00091 gps_on = 0; 00092 gps_xstandby = 0; 00093 } 00094 00095 //heartbeat 00096 pulse = 1; 00097 wait(0.2); 00098 pulse = 0; 00099 wait(0.2); 00100 } 00101 }
Generated on Tue Jul 12 2022 15:22:49 by
