Hi All
I'm beginner in arduino and i try to read number from file in SD card and based on this number pinmode will output ,
I have file "TST1" and it contain only number "1" , I need serial to read the file and if this number is "1" then pin 31 in arduino mega will output .
i tried with below but i got error
"exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560."
Code i tried :
/*
SD card read/write
*/
#include <SPI.h>
#include <SD.h>
File myFile;
int x = 0;
void setup()
{
pinMode (31,OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(53)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("TST1.TXT", FILE_READ);
// if the file opened okay, write to it:
if (myFile) {
while (myFile.available()) {
Serial.write(myFile.read());
}
if (Serial.available() > 0) {
x = Serial.read(); //gets one byte from serial buffer
if (x == 1) {
digitalWrite(31,HIGH);
}
myFile.close();
}
}
}
Any help !