ADXL345 test on L476

Dependencies:   mbed

Committer:
tifo
Date:
Wed Feb 07 16:05:59 2018 +0000
Revision:
4:d850da8732c1
Parent:
3:618d78c7c53a
buzzer added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tifo 0:a0f7c6807a3a 1 #include "mbed.h"
tifo 0:a0f7c6807a3a 2 #include "adxl345.h"
tifo 2:2a57e2a50796 3 #include <string>
tifo 0:a0f7c6807a3a 4
tifo 4:d850da8732c1 5 #define DEBUG // it doesnt use modem in debug mode. I dont have it and code will stack on my prototype cuz will never receive answers from modem.
tifo 4:d850da8732c1 6 // comment this line to turn off debug mode
tifo 4:d850da8732c1 7
tifo 2:2a57e2a50796 8 // skywire -------------------
tifo 2:2a57e2a50796 9 /* --CHANGE THIS FOR YOUR SETUP-- */
tifo 2:2a57e2a50796 10 #define DeviceID "yourDeviceIDhere" //Freeboard DweetIO unique ID
tifo 2:2a57e2a50796 11 /* --CHANGE THIS FOR YORU SETUP (IF APPLICABLE)-- */
tifo 2:2a57e2a50796 12 string APN = "yourAPNhere";
tifo 2:2a57e2a50796 13 // ===========================
tifo 0:a0f7c6807a3a 14
tifo 4:d850da8732c1 15 PwmOut mypwm(D3);
tifo 4:d850da8732c1 16 Ticker timer1;
tifo 4:d850da8732c1 17
tifo 0:a0f7c6807a3a 18 ADXL345 adxl;
tifo 0:a0f7c6807a3a 19
tifo 0:a0f7c6807a3a 20 int x, y, z;
tifo 0:a0f7c6807a3a 21
tifo 1:2098adebc6da 22 volatile char input_buffer[90]; // store everything received
tifo 1:2098adebc6da 23 volatile char message_buffer[90]; // store message
tifo 1:2098adebc6da 24 volatile char input_buffer_counter = 0;
tifo 1:2098adebc6da 25 volatile char message_counter = 0;
tifo 1:2098adebc6da 26 volatile char input_flag = false;
tifo 1:2098adebc6da 27
tifo 2:2a57e2a50796 28 volatile char latitude[15] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
tifo 2:2a57e2a50796 29 volatile char longtitude[15] = {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};
tifo 1:2098adebc6da 30 volatile char coorFlag = 0;
tifo 1:2098adebc6da 31
tifo 4:d850da8732c1 32 volatile int period = 1000; // buzzer variables
tifo 4:d850da8732c1 33 volatile int rising = 1;
tifo 4:d850da8732c1 34
tifo 1:2098adebc6da 35
tifo 2:2a57e2a50796 36 // skywire ------------------------
tifo 2:2a57e2a50796 37 DigitalOut skywire_en(PA_6); // Skywire Enable
tifo 2:2a57e2a50796 38 DigitalOut skywire_rts(PA_7); // Skywire Send
tifo 2:2a57e2a50796 39 Serial skywire(PA_9,PA_10); // Serial comms to Skywire
tifo 2:2a57e2a50796 40 // Variables for UART comms
tifo 2:2a57e2a50796 41 volatile int rx_in=0;
tifo 2:2a57e2a50796 42 volatile int rx_out=0;
tifo 2:2a57e2a50796 43 const int buffer_size = 600;
tifo 2:2a57e2a50796 44 char rx_buffer[buffer_size+1];
tifo 2:2a57e2a50796 45 char rx_line[buffer_size];
tifo 2:2a57e2a50796 46 // char array for reading from Skywire
tifo 2:2a57e2a50796 47 char str[255];
tifo 2:2a57e2a50796 48 // ===============================
tifo 2:2a57e2a50796 49
tifo 2:2a57e2a50796 50 Serial pcSerial(SERIAL_TX, SERIAL_RX, 9600); // tx, rx // pc
tifo 2:2a57e2a50796 51 Serial gpsSerial(A0, A1, 9600); // tx, rx // gps
tifo 0:a0f7c6807a3a 52
tifo 0:a0f7c6807a3a 53 I2C i2cAcc(I2C_SDA, I2C_SCL);
tifo 0:a0f7c6807a3a 54
tifo 2:2a57e2a50796 55 DigitalOut led(LED1);
tifo 2:2a57e2a50796 56
tifo 0:a0f7c6807a3a 57 void ADXL_ISR();
tifo 1:2098adebc6da 58 void rxHandler();
tifo 4:d850da8732c1 59 void data_send();
tifo 4:d850da8732c1 60 void alarm_on();
tifo 4:d850da8732c1 61 void alarm_off();
tifo 0:a0f7c6807a3a 62
tifo 0:a0f7c6807a3a 63
tifo 0:a0f7c6807a3a 64
tifo 2:2a57e2a50796 65 //===================================================================
tifo 2:2a57e2a50796 66 //FUNCTIONS
tifo 2:2a57e2a50796 67 //===================================================================
tifo 0:a0f7c6807a3a 68 /********************* ISR *********************/
tifo 0:a0f7c6807a3a 69 /* Look for Interrupts and Triggered Action */
tifo 0:a0f7c6807a3a 70 void ADXL_ISR() {
tifo 0:a0f7c6807a3a 71
tifo 0:a0f7c6807a3a 72 // getInterruptSource clears all triggered actions after returning value
tifo 0:a0f7c6807a3a 73 // Do not call again until you need to recheck for triggered actions
tifo 0:a0f7c6807a3a 74 int interrupts = adxl.getInterruptSource();
tifo 0:a0f7c6807a3a 75
tifo 0:a0f7c6807a3a 76 // Free Fall Detection
tifo 0:a0f7c6807a3a 77 if(adxl.triggered(interrupts, ADXL345_FREE_FALL)){
tifo 2:2a57e2a50796 78 pcSerial.printf("*** FREE FALL ***\n");
tifo 2:2a57e2a50796 79
tifo 4:d850da8732c1 80 alarm_on(); // turn of alarm
tifo 4:d850da8732c1 81 led = 1; // turn led on
tifo 4:d850da8732c1 82
tifo 4:d850da8732c1 83 #ifndef DEBUG
tifo 4:d850da8732c1 84 data_send(); // send data if not in debug mode
tifo 4:d850da8732c1 85 #else
tifo 4:d850da8732c1 86 wait(10); // just wait if in debug
tifo 4:d850da8732c1 87 #endif
tifo 4:d850da8732c1 88
tifo 4:d850da8732c1 89 alarm_off(); // turn alarm off
tifo 4:d850da8732c1 90 led = 0; // turn led off
tifo 0:a0f7c6807a3a 91 }
tifo 0:a0f7c6807a3a 92 }
tifo 0:a0f7c6807a3a 93
tifo 2:2a57e2a50796 94 //===================================================================
tifo 1:2098adebc6da 95 // RX interrupt handler
tifo 1:2098adebc6da 96 // stores everything into input_buffer
tifo 1:2098adebc6da 97 void rxHandler()
tifo 1:2098adebc6da 98 {
tifo 1:2098adebc6da 99 char tmp;
tifo 1:2098adebc6da 100
tifo 1:2098adebc6da 101 do
tifo 1:2098adebc6da 102 {
tifo 1:2098adebc6da 103 tmp = gpsSerial.getc(); // read serial data
tifo 1:2098adebc6da 104
tifo 1:2098adebc6da 105 if(tmp == '$') // if message start character( every nmea message starts with $)
tifo 1:2098adebc6da 106 {
tifo 1:2098adebc6da 107 input_buffer_counter = 0; // reset inut buffer counter
tifo 1:2098adebc6da 108 return;
tifo 1:2098adebc6da 109 }
tifo 1:2098adebc6da 110
tifo 1:2098adebc6da 111 if(tmp == '*') // if end of message( every nmea message ends with *+CRC)
tifo 2:2a57e2a50796 112 {
tifo 2:2a57e2a50796 113 input_buffer[input_buffer_counter] = tmp;
tifo 2:2a57e2a50796 114 input_buffer_counter++;
tifo 1:2098adebc6da 115 if(input_buffer[3] == 'L') // if nmea string type is GPGLL
tifo 1:2098adebc6da 116 {
tifo 1:2098adebc6da 117 int t = 0;
tifo 1:2098adebc6da 118 int lat = 0;
tifo 1:2098adebc6da 119 int lon = 0;
tifo 1:2098adebc6da 120
tifo 2:2a57e2a50796 121 for(int i=0; i<15; i++) // clear latitude and longtitude
tifo 1:2098adebc6da 122 {
tifo 1:2098adebc6da 123 latitude[lat++] = ' ';
tifo 1:2098adebc6da 124 longtitude[lon++] = ' ';
tifo 1:2098adebc6da 125 }
tifo 1:2098adebc6da 126
tifo 1:2098adebc6da 127 while(input_buffer[t] != ',') // find coma after GPGLL
tifo 1:2098adebc6da 128 t++; // t points coma after GPGLL
tifo 1:2098adebc6da 129
tifo 1:2098adebc6da 130 t++; // set to to first latitude character
tifo 1:2098adebc6da 131
tifo 1:2098adebc6da 132
tifo 1:2098adebc6da 133 lat = 0;
tifo 1:2098adebc6da 134
tifo 1:2098adebc6da 135 while(input_buffer[t] != ',') // copy latitude value
tifo 1:2098adebc6da 136 {
tifo 1:2098adebc6da 137 latitude[lat] = input_buffer[t];
tifo 1:2098adebc6da 138 lat++;
tifo 1:2098adebc6da 139 t++; // t points coma after latitude
tifo 1:2098adebc6da 140 }
tifo 1:2098adebc6da 141 latitude[lat] = input_buffer[t]; // copy coma
tifo 2:2a57e2a50796 142 lat++;
tifo 1:2098adebc6da 143 t++;
tifo 1:2098adebc6da 144 latitude[lat] = input_buffer[t]; // copy N or S direction
tifo 2:2a57e2a50796 145 lat++;
tifo 1:2098adebc6da 146 t++;
tifo 2:2a57e2a50796 147 latitude[lat] = '\0'; // write null character
tifo 1:2098adebc6da 148
tifo 1:2098adebc6da 149 t++; // set t to first character of longtitude
tifo 1:2098adebc6da 150
tifo 1:2098adebc6da 151
tifo 1:2098adebc6da 152 lon = 0;
tifo 1:2098adebc6da 153
tifo 1:2098adebc6da 154 while(input_buffer[t] != ',') // copy longtitude value
tifo 1:2098adebc6da 155 {
tifo 1:2098adebc6da 156 longtitude[lon] = input_buffer[t];
tifo 1:2098adebc6da 157 lon++;
tifo 1:2098adebc6da 158 t++; // t points coma after longtitude
tifo 1:2098adebc6da 159 }
tifo 1:2098adebc6da 160 longtitude[lon] = input_buffer[t]; // copy coma
tifo 2:2a57e2a50796 161 lon++;
tifo 1:2098adebc6da 162 t++;
tifo 1:2098adebc6da 163 longtitude[lon] = input_buffer[t]; // copy W or E direction
tifo 2:2a57e2a50796 164 lon++;
tifo 2:2a57e2a50796 165 longtitude[lon] = '\0'; // write null character
tifo 1:2098adebc6da 166
tifo 2:2a57e2a50796 167 coorFlag = 1;
tifo 1:2098adebc6da 168 }
tifo 1:2098adebc6da 169 return;
tifo 1:2098adebc6da 170 }
tifo 1:2098adebc6da 171 input_buffer[input_buffer_counter] = tmp;
tifo 1:2098adebc6da 172 input_buffer_counter++;
tifo 1:2098adebc6da 173 }
tifo 1:2098adebc6da 174 while(gpsSerial.readable());
tifo 1:2098adebc6da 175 }
tifo 1:2098adebc6da 176
tifo 2:2a57e2a50796 177 //===================================================================
tifo 2:2a57e2a50796 178 // Read line from the UART
tifo 2:2a57e2a50796 179 void read_line()
tifo 2:2a57e2a50796 180 {
tifo 2:2a57e2a50796 181 int i;
tifo 2:2a57e2a50796 182 i = 0;
tifo 2:2a57e2a50796 183 // Start Critical Section - don't interrupt while changing global buffer variables
tifo 2:2a57e2a50796 184 __disable_irq();
tifo 2:2a57e2a50796 185 // Loop reading rx buffer characters until end of line character
tifo 2:2a57e2a50796 186 while ((i==0) || (rx_line[i-1] != '\n')) {
tifo 2:2a57e2a50796 187 // Wait if buffer empty
tifo 2:2a57e2a50796 188 if (rx_in == rx_out) {
tifo 2:2a57e2a50796 189 // End Critical Section - need to allow rx interrupt to get new characters for buffer
tifo 2:2a57e2a50796 190 __enable_irq();
tifo 2:2a57e2a50796 191 while (rx_in == rx_out) {
tifo 2:2a57e2a50796 192 }
tifo 2:2a57e2a50796 193 // Start Critical Section - don't interrupt while changing global buffer variables
tifo 2:2a57e2a50796 194 __disable_irq();
tifo 2:2a57e2a50796 195 }
tifo 2:2a57e2a50796 196 rx_line[i] = rx_buffer[rx_out];
tifo 2:2a57e2a50796 197 i++;
tifo 2:2a57e2a50796 198 rx_out = (rx_out + 1) % buffer_size;
tifo 2:2a57e2a50796 199 }
tifo 2:2a57e2a50796 200 // End Critical Section
tifo 2:2a57e2a50796 201 __enable_irq();
tifo 2:2a57e2a50796 202 rx_line[i-1] = 0;
tifo 2:2a57e2a50796 203 return;
tifo 2:2a57e2a50796 204 }
tifo 1:2098adebc6da 205
tifo 2:2a57e2a50796 206 //=======================================================================
tifo 2:2a57e2a50796 207 // Wait for specific response
tifo 2:2a57e2a50796 208 int WaitForResponse(char* response, int num)
tifo 2:2a57e2a50796 209 {
tifo 2:2a57e2a50796 210 do {
tifo 2:2a57e2a50796 211 read_line();
tifo 2:2a57e2a50796 212 pcSerial.printf("Waiting for: %s, Recieved: %s\r\n", response, rx_line);
tifo 2:2a57e2a50796 213 } while (strncmp(rx_line, response, num));
tifo 2:2a57e2a50796 214 return 0;
tifo 2:2a57e2a50796 215 }
tifo 2:2a57e2a50796 216
tifo 2:2a57e2a50796 217 //==========================================================================
tifo 2:2a57e2a50796 218 // Interrupt for the Skywire
tifo 2:2a57e2a50796 219 void Skywire_Rx_interrupt()
tifo 2:2a57e2a50796 220 {
tifo 2:2a57e2a50796 221 // Loop just in case more than one character is in UART's receive FIFO buffer
tifo 2:2a57e2a50796 222 // Stop if buffer full
tifo 2:2a57e2a50796 223 while ((skywire.readable()) && (((rx_in + 1) % buffer_size) != rx_out)) {
tifo 2:2a57e2a50796 224 rx_buffer[rx_in] = skywire.getc();
tifo 2:2a57e2a50796 225 rx_in = (rx_in + 1) % buffer_size;
tifo 2:2a57e2a50796 226 }
tifo 2:2a57e2a50796 227 return;
tifo 2:2a57e2a50796 228 }
tifo 2:2a57e2a50796 229
tifo 2:2a57e2a50796 230 void data_send()
tifo 2:2a57e2a50796 231 {
tifo 2:2a57e2a50796 232 skywire.printf("AT+SQNSD=3,0,80,\"dweet.io\"\r\n");
tifo 2:2a57e2a50796 233 WaitForResponse("CONNECT", 7);
tifo 2:2a57e2a50796 234
tifo 2:2a57e2a50796 235 pcSerial.printf("Sending information...\r\n");
tifo 2:2a57e2a50796 236 // Report the sensor data to dweet.io
tifo 2:2a57e2a50796 237 skywire.printf("POST /dweet/for/%s?latitude=%s&longtitude=%s HTTP/1.0\r\n\r\n", DeviceID, latitude, longtitude);
tifo 2:2a57e2a50796 238
tifo 2:2a57e2a50796 239 // Wait for response from dweet.io
tifo 2:2a57e2a50796 240 WaitForResponse("OK", 2);
tifo 2:2a57e2a50796 241 wait(1);
tifo 2:2a57e2a50796 242 }
tifo 2:2a57e2a50796 243
tifo 4:d850da8732c1 244 void modem_init()
tifo 4:d850da8732c1 245 {
tifo 2:2a57e2a50796 246 //Enable Skywire
tifo 2:2a57e2a50796 247 skywire_en=0;
tifo 2:2a57e2a50796 248 wait(2);
tifo 2:2a57e2a50796 249 skywire_en=1;
tifo 2:2a57e2a50796 250 wait(2);
tifo 2:2a57e2a50796 251 skywire_en=0;
tifo 2:2a57e2a50796 252
tifo 2:2a57e2a50796 253 // Wait for modem to initialize
tifo 2:2a57e2a50796 254 wait(60);
tifo 2:2a57e2a50796 255
tifo 2:2a57e2a50796 256 //Turn off echo
tifo 2:2a57e2a50796 257 // Helps with checking responses from Skywire
tifo 2:2a57e2a50796 258 pcSerial.printf("Turning off echo...\r\n");
tifo 2:2a57e2a50796 259 skywire.printf("ATE0\r\n");
tifo 2:2a57e2a50796 260 WaitForResponse("OK", 2);
tifo 2:2a57e2a50796 261
tifo 2:2a57e2a50796 262 // Turn on DNS Response Caching
tifo 2:2a57e2a50796 263 // Used on the Telit-based Skywires
tifo 2:2a57e2a50796 264 pcSerial.printf("Turning on DNS Cacheing to improve speed...");
tifo 2:2a57e2a50796 265 skywire.printf("AT#CACHEDNS=1\r\n");
tifo 2:2a57e2a50796 266 WaitForResponse("OK", 2);
tifo 2:2a57e2a50796 267
tifo 2:2a57e2a50796 268 pcSerial.printf("Connecting to Network...\r\n");
tifo 2:2a57e2a50796 269 // get IP address
tifo 2:2a57e2a50796 270 // The last parameter in AT+SQNSCFG sets the timeout if transmit buffer is not full
tifo 2:2a57e2a50796 271 // Time is in hundreds of ms: so, a value of 5 = 500ms
tifo 2:2a57e2a50796 272 pcSerial.printf("Configuring context part 1...\r\n");
tifo 2:2a57e2a50796 273 skywire.printf("AT+SQNSCFG=3,3,300,90,600,5\r\n");
tifo 2:2a57e2a50796 274 WaitForResponse("OK", 2);
tifo 2:2a57e2a50796 275 wait(1);
tifo 2:2a57e2a50796 276 pcSerial.printf("Configuring context part 2...\r\n");
tifo 2:2a57e2a50796 277 skywire.printf("AT+CGDCONT=3,\"IP\",\"vzwinternet\"\r\n");
tifo 2:2a57e2a50796 278 WaitForResponse("OK", 2);
tifo 2:2a57e2a50796 279 wait(1);
tifo 2:2a57e2a50796 280 pcSerial.printf("Activating context...\r\n");
tifo 2:2a57e2a50796 281 skywire.printf("AT+CGACT=1,3\r\n");
tifo 2:2a57e2a50796 282 WaitForResponse("OK", 2);
tifo 4:d850da8732c1 283 }
tifo 4:d850da8732c1 284
tifo 4:d850da8732c1 285 // interrupt using for encreasing/decreasing tone
tifo 4:d850da8732c1 286 void attime()
tifo 4:d850da8732c1 287 {
tifo 2:2a57e2a50796 288
tifo 4:d850da8732c1 289 if(rising == 1)
tifo 4:d850da8732c1 290 {
tifo 4:d850da8732c1 291 if(period < 1500)
tifo 4:d850da8732c1 292 period += 19;
tifo 4:d850da8732c1 293 else
tifo 4:d850da8732c1 294 rising = 0;
tifo 4:d850da8732c1 295 }
tifo 4:d850da8732c1 296 else
tifo 4:d850da8732c1 297 {
tifo 4:d850da8732c1 298 if(period > 1000)
tifo 4:d850da8732c1 299 period -= 19;
tifo 4:d850da8732c1 300 else
tifo 4:d850da8732c1 301 rising = 1;
tifo 4:d850da8732c1 302 }
tifo 4:d850da8732c1 303
tifo 4:d850da8732c1 304 mypwm.period_us(period);
tifo 4:d850da8732c1 305 mypwm.pulsewidth_us(period/2);
tifo 4:d850da8732c1 306 }
tifo 4:d850da8732c1 307
tifo 4:d850da8732c1 308 // turn alarm sound on
tifo 4:d850da8732c1 309 void alarm_on()
tifo 4:d850da8732c1 310 {
tifo 4:d850da8732c1 311 timer1.attach(&attime, 0.01);
tifo 4:d850da8732c1 312 }
tifo 4:d850da8732c1 313
tifo 4:d850da8732c1 314 // turn alarm sound off
tifo 4:d850da8732c1 315 void alarm_off()
tifo 4:d850da8732c1 316 {
tifo 4:d850da8732c1 317 mypwm.pulsewidth(0);
tifo 4:d850da8732c1 318 timer1.detach();
tifo 4:d850da8732c1 319 }
tifo 4:d850da8732c1 320
tifo 4:d850da8732c1 321
tifo 4:d850da8732c1 322
tifo 4:d850da8732c1 323 // MAIN -=-=-=-=-=-=-=-=-
tifo 4:d850da8732c1 324 //++++++++++++++++++++++++++++++++++++++++++++++++++++
tifo 4:d850da8732c1 325 int main() {
tifo 4:d850da8732c1 326
tifo 4:d850da8732c1 327 skywire.baud(115200);
tifo 4:d850da8732c1 328 skywire.attach(&Skywire_Rx_interrupt, Serial::RxIrq);
tifo 4:d850da8732c1 329
tifo 4:d850da8732c1 330 i2cAcc.frequency(100000);
tifo 4:d850da8732c1 331
tifo 4:d850da8732c1 332 adxl.powerOn(); // Power on the ADXL345
tifo 4:d850da8732c1 333
tifo 4:d850da8732c1 334 adxl.setRangeSetting(8); // Give the range settings
tifo 4:d850da8732c1 335 // Accepted values are 2g, 4g, 8g or 16g
tifo 4:d850da8732c1 336 // Higher Values = Wider Measurement Range
tifo 4:d850da8732c1 337 // Lower Values = Greater Sensitivity
tifo 4:d850da8732c1 338
tifo 4:d850da8732c1 339 // Set values for what is considered FREE FALL (0-255)
tifo 4:d850da8732c1 340 adxl.setFreeFallThreshold(9); // (5 - 9) recommended - 62.5mg per increment
tifo 4:d850da8732c1 341 adxl.setFreeFallDuration(15); // (20 - 70) recommended - 5ms per increment
tifo 4:d850da8732c1 342
tifo 4:d850da8732c1 343 // Setting all interupts to take place on INT1 pin
tifo 4:d850da8732c1 344 adxl.setImportantInterruptMapping(0, 0, 1, 0, 0); // Sets "adxl.setEveryInterruptMapping(single tap, double tap, free fall, activity, inactivity);"
tifo 4:d850da8732c1 345 // Accepts only 1 or 2 values for pins INT1 and INT2. This chooses the pin on the ADXL345 to use for Interrupts.
tifo 4:d850da8732c1 346 // This library may have a problem using INT2 pin. Default to INT1 pin.
tifo 4:d850da8732c1 347
tifo 4:d850da8732c1 348 // Turn on Interrupts for each mode (1 == ON, 0 == OFF)
tifo 4:d850da8732c1 349 adxl.FreeFallINT(1);
tifo 4:d850da8732c1 350
tifo 4:d850da8732c1 351
tifo 4:d850da8732c1 352
tifo 4:d850da8732c1 353 pcSerial.printf("SparkFun ADXL345 Accelerometer Hook Up Guide Example\n");
tifo 4:d850da8732c1 354
tifo 4:d850da8732c1 355 gpsSerial.attach(rxHandler);
tifo 4:d850da8732c1 356
tifo 4:d850da8732c1 357 #ifndef DEBUG // if not debug mode
tifo 4:d850da8732c1 358 pcSerial.printf("Starting Demo...\r\n");
tifo 4:d850da8732c1 359 pcSerial.printf("Waiting for Skywire to Boot...\r\n");
tifo 4:d850da8732c1 360
tifo 4:d850da8732c1 361 modem_init(); // init modem
tifo 4:d850da8732c1 362 #endif
tifo 2:2a57e2a50796 363
tifo 2:2a57e2a50796 364
tifo 2:2a57e2a50796 365 while(1) {
tifo 2:2a57e2a50796 366
tifo 2:2a57e2a50796 367 // Accelerometer Readings
tifo 2:2a57e2a50796 368 //int x,y,z;
tifo 2:2a57e2a50796 369 //adxl.readAccel(&x, &y, &z); // Read the accelerometer values and store them in variables declared above x,y,z
tifo 2:2a57e2a50796 370
tifo 2:2a57e2a50796 371 // Output Results to Serial
tifo 2:2a57e2a50796 372 /* UNCOMMENT TO VIEW X Y Z ACCELEROMETER VALUES */
tifo 2:2a57e2a50796 373 //mySerial.printf("X: %i\nY: %i\nZ: %i\n================\n", x, y, z);
tifo 2:2a57e2a50796 374 //wait(2);
tifo 2:2a57e2a50796 375
tifo 2:2a57e2a50796 376 ADXL_ISR();
tifo 2:2a57e2a50796 377 // You may also choose to avoid using interrupts and simply run the functions within ADXL_ISR();
tifo 2:2a57e2a50796 378 // and place it within the loop instead.
tifo 2:2a57e2a50796 379 // This may come in handy when it doesn't matter when the action occurs.
tifo 2:2a57e2a50796 380
tifo 2:2a57e2a50796 381
tifo 2:2a57e2a50796 382 if(coorFlag) // show coordinates
tifo 2:2a57e2a50796 383 {
tifo 2:2a57e2a50796 384 pcSerial.printf("message: %s\n", input_buffer);
tifo 2:2a57e2a50796 385 pcSerial.printf("latitude: %s\n", latitude);
tifo 2:2a57e2a50796 386 pcSerial.printf("longtitude: %s\n", longtitude);
tifo 2:2a57e2a50796 387
tifo 4:d850da8732c1 388 #ifndef DEBUG
tifo 2:2a57e2a50796 389 data_send();
tifo 4:d850da8732c1 390 #endif
tifo 2:2a57e2a50796 391
tifo 2:2a57e2a50796 392 coorFlag = 0;
tifo 2:2a57e2a50796 393 }
tifo 2:2a57e2a50796 394
tifo 2:2a57e2a50796 395
tifo 2:2a57e2a50796 396
tifo 2:2a57e2a50796 397 }
tifo 2:2a57e2a50796 398 }
tifo 2:2a57e2a50796 399
tifo 2:2a57e2a50796 400
tifo 2:2a57e2a50796 401
tifo 2:2a57e2a50796 402