Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SD.h>
- File myFile;
- int recebido = 0; //variável que receberá os dados da porta serial
- //int led = 2;
- void setup(){
- Serial.begin(9600);//frequência da porta serial
- Serial.print("Initializing SD card...");
- // pinMode(led, OUTPUT);
- if (!SD.begin(4)) {
- Serial.println("initialization failed!");
- return;
- }
- Serial.println("initialization done.");
- myFile = SD.open("test.txt", FILE_WRITE);
- // if the file opened okay, write to it:
- if (myFile) {
- myFile.println("26/07/2014 TESTE 1");
- myFile.close();
- }
- }
- void loop(){
- myFile = SD.open("test.txt", FILE_WRITE);
- // if the file opened okay, write to it:
- if (myFile) {
- Serial.print("O resultado do sensor: ");
- Serial.println(analogRead(A0));
- // digitalWrite(led,HIGH);
- myFile.println(analogRead(A0));
- // close the file:
- myFile.close();
- } else {
- // if the file didn't open, print an error:
- Serial.println("error opening test.txt");
- }
- if(Serial.available() > 0) {
- recebido = Serial.read();
- if(recebido == 'a') {
- SD.remove ("test.txt");
- if (!SD.exists ("test.txt") ){
- Serial.println ("Arquivo apagado com sucesso");
- }else{
- Serial.println ("Erro ao apagar arquivo!");
- }
- }
- if(recebido == 'b'){
- myFile = SD.open("test.txt");
- if (myFile) {
- Serial.println("test.txt:");
- // read from the file until there's nothing else in it:
- while (myFile.available()) {
- Serial.write(myFile.read());
- }
- // close the file:
- myFile.close();
- } else {
- // if the file didn't open, print an error:
- Serial.println("error opening test.txt");
- }
- }//FECHA IF PRINCIPAL
- }
- // digitalWrite(led,LOW);
- delay(30000);
- }
Advertisement
Add Comment
Please, Sign In to add comment