Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include "RTClib.h"
- #include <SPI.h>
- #include <SD.h>
- RTC_DS1307 rtc;
- char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
- const int chipSelect = 4;
- int sensor1=30, sensor2=25, sensor3=90;
- int ano,dia,mes,hora,minuto,segundo;
- char sem;
- File dataFile;
- void setup()
- {
- Serial.begin(9600);
- //********************** Iniciando o RTC ***************************************
- if (! rtc.begin())
- {
- Serial.println("RTC Não Encontrado");
- while (1);
- }
- if (! rtc.isrunning())
- {
- Serial.println("RTC is NOT running!");
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- rtc.adjust(DateTime(2015, 1, 21, 3, 0, 0));
- }
- delay(500);
- //********************** Inicando o SD ***************************************
- Serial.print("Initializing SD card...");
- // make sure that the default chip select pin is set to
- // output, even if you don't use it:
- pinMode(SS, OUTPUT);
- // see if the card is present and can be initialized:
- if (!SD.begin(chipSelect)) {
- Serial.println("Card failed, or not present");
- // don't do anything more:
- while (1) ;
- }
- Serial.println("card initialized.");
- //********************** Cria o Arquivo no SD ***************************************
- // Open up the file we're going to log to!
- dataFile = SD.open("teste.txt", FILE_WRITE);
- if (! dataFile) {
- Serial.println("error opening datalog.txt");
- // Wait forever since we cant write data
- while (1) ;
- }
- }
- void loop()
- {
- DateTime now = rtc.now();
- ano=now.year();
- mes=now.month();
- dia=now.day();
- hora=now.hour();
- minuto=now.minute();
- segundo=now.second();
- dataFile = SD.open("teste.txt", FILE_WRITE);
- dataFile.print(String(dia));
- dataFile.print('/');
- dataFile.print(String(mes));
- dataFile.print('/');
- dataFile.print(String(ano));
- dataFile.print(" (");
- dataFile.print(daysOfTheWeek[now.dayOfTheWeek()]);
- dataFile.print(") ");
- dataFile.print(String(hora));
- dataFile.print(':');
- dataFile.print(String(minuto));
- dataFile.print(':');
- dataFile.print(String(segundo));
- dataFile.print('|');
- dataFile.print(String(sensor1));
- dataFile.print('|');
- dataFile.print(String(sensor2));
- dataFile.print('|');
- dataFile.print(String(sensor3));
- dataFile.println();
- Serial.print(hora);
- Serial.print(':');
- Serial.print(minuto);
- Serial.print(':');
- Serial.print(segundo);
- Serial.print(':');
- Serial.println("Salvo");
- dataFile.close();
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement