Hi all, I'm trying to make a device that tracks motion with a GPS module, a MicroSD card module, an Arduino and a couple of switch buttons. The device is meant to track the path of a pedestrian, who walks in straight lines. The two buttons are marked "left" and "right". When the pedestrian makes a left (or right) turn, he/she presses on the "left" (or "right") button, and the Arduino saves the current GPS coordinates + "L" for left (or "R" for right).
This is my code:
#include <SPI.h>
#include <SD.h>
const int errorLED = 13;
const int statusLED = 12;
const int chipSelect = 53;
float tmFix = 0;
float lat = 0;
float longt = 0;
int addr = 0;
void setup() {
Serial1.begin(9600);
Serial.begin(9600);
digitalWrite(13, LOW);
attachInterrupt(0, left, RISING);
attachInterrupt(1, right, RISING);
pinMode(13, OUTPUT);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
digitalWrite(errorLED, LOW);
}
void loop() {
String GPSdata = "";
if (Serial1.available() > 0) {
if (Serial1.find("$GNRMC") == true) {
tmFix = Serial1.parseFloat();
lat = Serial1.parseFloat();
longt = Serial1.parseFloat();
}
GPSdata += String(lat);
GPSdata += ",";
GPSdata += String(longt);
}
}
void left() {
GPSdata += ",";
GPSdata += "L";
File dataFile = SD.open("datalog.txt", FILE_WRITE);
dataFile.println(GPSdata);
dataFile.close();
digitalWrite(statusLED, HIGH);
delayMicroseconds(500000);
digitalWrite(statusLED, LOW);
}
void right() {
GPSdata += ",";
GPSdata += "R";
digitalWrite(statusLED, HIGH);
delayMicroseconds(500000);
digitalWrite(statusLED, LOW);
}
and this is the error message:
"
Arduino: 1.6.6 Hourly Build 2015/08/19 10:30 (Windows 8.1), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
GPSparseFloat.ino: In function 'void left()':
GPSparseFloat:36: error: 'GPSdata' was not declared in this scope
GPSparseFloat.ino: In function 'void right()':
GPSparseFloat:46: error: 'GPSdata' was not declared in this scope
'GPSdata' was not declared in this scope
"
Is there a way I can share the string GPSdata across the left() and right() voids? eg make GPSdata a global string?
An help is appreciated!