Hi,
I'm working on this program which reads 4 text files from the SD card reader (File names are: Book1.txt,Book2.txt....).
The program check the size of the file, multiply it by 100 and use this number for On-Time of an LED.
It runs just fine, until the 7th loop of the program. then, after it reads Book2.txt, the program stop responding (i think) and the LED is blinking with low light and with constant intervals.
Pressing RESET button solve the problem until it reaches the 7th loop again.
#include <SD.h>
File myFile;
int relay = 2;
void setup() {
pinMode(relay, OUTPUT);
pinMode(10, OUTPUT);
SD.begin(4);
}
void loop() {
for(int i=1;i<5;i++)
{
String temp = "Book";
temp.concat(i);
temp.concat(".txt");
char filename[temp.length()+1];
temp.toCharArray(filename, sizeof(filename));
myFile=SD.open(filename);
int ontime =100* myFile.size();
digitalWrite(relay,HIGH);
delay(ontime);
digitalWrite(relay, LOW);
delay(1000);
}
}
Any ideas?
Thanks.