I am trying to turn SD logging on and off with a push button... I am displaying values on an LCD screen and then want to be able to log the values by pressing a button and then turn off the logging by pressing a button. I have the values displaying to a screen but when I trigger the logging function, the screen locks up and no logging is actually done either. Everything seems to just lock.
The switch function is:
void loggerbutton(){
logtemp = logger;
if (logtemp == 0)
logger = 1;
if (logtemp == 1)
logger = 0;
switch(logger){
case 0:
//log button
myGLCD.setColor(255, 0, 0);
myGLCD.fillRoundRect(183, 0, 284, 119); //top log box
myGLCD.setBackColor(255, 0, 0);
myGLCD.setColor(0, 0, 0);
myGLCD.print("LOG", 208, 60);
myGLCD.print("Off", 208, 75);
break;
case 1:
loggerinit();
//log button
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect(183, 0, 284, 119); //top log box
myGLCD.setBackColor(0, 255, 0);
myGLCD.setColor(0, 0, 0);
myGLCD.print("LOG", 208, 60);
myGLCD.print("On", 208, 75);
break;
default:
break;
}
}
The logger function (abbreviated) is:
void loggerinit()
{
// initialize the SD card
if (!card.init()) error("card.init");
// initialize a FAT volume
if (!volume.init(card)) error("volume.init");
// open root directory
if (!root.openRoot(volume)) error("openRoot");
// create a new file
char name[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
name[6] = i/10 + '0';
name[7] = i%10 + '0';
if (file.open(root, name, O_CREAT | O_EXCL | O_WRITE)) break;
}
if (!file.isOpen()) error ("file.create");
// write header
file.writeError = 0;
file.println("time,lat,long,speed,date,xA,xE,yA,yE,zA,zE,lean,leane,dive,dive_e,T1mp,RPM,V,TPS,Frt,Rear,AFR,Fork,shock");
// attempt to write out the header to the file
if (file.writeError || !file.sync()) {
error("write header");
}
}
And in the loop function:
//Check For Touchscreen Press
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((x>=10) && (x<=60)) // Upper row
{
if ((y>=10) && (y<=100)) // Button: Next
{
ButtonAPressed();
}
if ((y>=130) && (y<=229)) // Button: Prev
{
ButtonBPressed();
}
}
if ((x>=160) && (x<=240)) // Upper row
{
if ((y>=10) && (y<=100)) // Button: Log
{
loggerbutton();
}
}
}
}
Is this just not possible or what am I doing wrong?