Hello everyone, I have to read the content of a variable from a .txt and an .htm file. I also have to write other thing in this txt/htm file but th funtion file.print(); doesn't work. The listing is:
#include <SPI.h> //LIBRERIA PER COMUNICAZIONE
#include <SD.h> //LIBRERIA PER CONTROLLO SD
File file,myFile; //DICHIARO FILE DI NOME "file"
int a=1;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
Serial.print("Initializing SD card...");
//INIZIALIZZAZIONE SCHEDA SD
if (!SD.begin(4)) { //) CONTROLLA SE LA SD E' SUL PIN 4
Serial.println("initialization failed!"); //) E' NECESSARIO CHE LA SD SIA SUL PIN 4
return; //) PER LA ETHERNET SHIELD
}
Serial.println("initialization done.");
myFile = SD.open("test.txt");
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();}
file = SD.open("prova.htm"); // APRE IL FILE "pagina.txt" (NOME REALE DEL FILE)
if (file) {
//Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (file.available()) { //CONTROLLA SE CI SONO ALTRI BYTE DEL FILE DA LEGGERE
Serial.write(file.read()); //INVIA I DATI IN FORMATO CARATTERE
}
file.print(a);
file.close(); //CHIUDE IL FILE
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}
Please answear me as soon as possible. If you're italian answear me in italian. Thank you