I made this code just for testing purpose, I wanted to read an integer from txt file stored in SD card and use that value to control led on off delay !
the integer is extracted fine, but the LED is not turning On or OFF, ive tried putting a constant instead of the value in the txt file but it is still not working. the code in the void setup seems to run fine, i used serial communication to read various values to check correct working.
#include <SD.h>
#include <stdlib.h>
File duty;
int input =0;
void setup()
{
pinMode (13, OUTPUT);
Serial.begin(9600);
Serial.print ("Initializing Card....");
pinMode(10, OUTPUT);
if (!SD.begin(10))
{
Serial.println ("Card Initialization Failed !");
return;
}
Serial.println ("Initialization Complete");
char buffer[10];
int index = 0;
for(int i = 0; i < 10; i++)
{
buffer[i] = NULL;
}
duty = SD.open ("duty.txt");
if (duty)
{
Serial.println("duty.txt:");
while (duty.available())
{
int num = duty.read();
if(num != 10)
{
//write in next location in buffer
buffer[index++] = num;
//Serial.println(buffer);
Serial.write(num);
}
input = atoi(buffer);
}
duty.close();
}
else
{
Serial.println("Error Opening Text");
}
Serial.end();
}
void loop()
{
digitalWrite (13, HIGH);
delay(input);
digitalWrite (13, LOW);
delay(input);
}