Hi, I'm running a GPS data tracking program on my Arduino Mega with a two-button interface. I am trying to blink an error LED if the SD card fails to initialize, and status LED whenever one of the buttons is pressed with the Timer library by Simon Monk. The two buttons are connected to EXT INT 0 and 1. The program loads, but the LED flash interval is much slower to what I set- when I set the oscillate period to 5ms the actual interval when I press a button is more like 1s. This is my code:
#include <Event.h>
#include <Timer.h>
#include <SPI.h>
#include <SD.h>
const int errorLED = 12;
const int statusLED = 11;
const int chipSelect = 53;
float tmFix = 0;
float lat = 0;
float longt = 0;
int addr = 0;
String GPSdata = "";
Timer t;
Timer E;
void setup() {
Serial1.begin(9600);
Serial.begin(9600);
digitalWrite(13, LOW);
attachInterrupt(0, left, CHANGE);
attachInterrupt(1, right, CHANGE);
pinMode(errorLED, OUTPUT);
pinMode(statusLED, OUTPUT);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
if (!SD.begin(chipSelect)) {
E.oscillate(errorLED, 5, LOW, 4);
}
else {
E.oscillate(statusLED, 5, LOW, 1);
}
E.update();
}
void loop() {
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);
}
t.update();
E.update();
}
void left() {
GPSdata += ",";
GPSdata += "L";
File dataFile = SD.open("datalog.txt", FILE_WRITE);
dataFile.println(GPSdata);
dataFile.close();
t.oscillate(statusLED, 5, LOW, 4);
t.update();
}
void right() {
GPSdata += ",";
GPSdata += "R";
t.oscillate(statusLED, 5, LOW, 4);
// t.update();
}
Why is the actual flash interval so slow?
An help will be appreciated!
Habib