I need help to get the syntax right in “struct sleepSt” below.
I’m sure the setup() function has errors as well, but can’t debug it until I get “struct sleepSt” syntax correct.
You all are WONDERFUL helpers. I’d be in big trouble if I didn’t have this forum to take me by the hand and lead the way.
#include <SPI.h>
#include <SD.h>
struct sleepSt
{
char hr[2];
char a;
char mn[2];
char b[4];
char level;
char c[4];
};
sleepSt sleepRec =
{
{'0','0'}, // hour
{':'},
{'0','0'}, // minute
{',',' ',' ',' '},
{' '}, // level
{' ',' ',' ','\n'}
};
File sleepF;
byte* sleepRecAr = (byte*)&sleepRec;
void setup()
{
Serial.begin(9600);
SD.begin(SS);
sleepF = SD.open("SLEEP101",FILE_WRITE);
sleepF.println("TIME: ,LEVEL:");
sleepRec.hr = "12";
sleepRec.mn = "45";
sleepRec.level = "3";
for (byte i=0; i<5; i++)
sleepF.write(sleepRecAr);
sleepF.close();
sleepRec.hr = "00";
sleepRec.mn = "00";
sleepRec.level = "0";
//////////////////////
sleepF = SD.open("SLEEP101",FILE_WRITE);
sleepRec = sleepF.read();
Serial.println(sleepRec.hr);
Serial.println(sleepRec.mn);
Serial.println(sleepRec.level);
sleepF.close();
}
void loop() {}
This sketch should save a file that looks like the below in a text editor:
TIME: ,LEVEL:
12:45 , 3
12:45 , 3
12:45 , 3
12:45 , 3
12:45 , 3