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>
- File myFile;
- RTC_DS1307 rtc;
- String stringOne;
- String Stringyear = "2010";
- String Stringmonth = "01";
- String Stringday = "01";
- unsigned long atual;
- unsigned long anterior = 0;
- const long intervalo = 60000;
- unsigned long val = 0.00;
- unsigned long s;
- float media;
- //-----------------------------------------------------------------
- void setup () {
- Serial.begin(115200);
- if (!SD.begin(15)) {
- return;
- }
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- while (1);
- }
- if (! rtc.isrunning()) {
- Serial.println("RTC is NOT running!");
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- }
- }
- //-----------------------------------------------------------------
- void loop () {
- DateTime now = rtc.now();
- if ((now.hour() == 17) && (now.minute() == 59) && (now.second() == 0))
- {
- Stringyear = now.year(), DEC;
- Stringmonth = now.month(), DEC;
- Stringday = now.day(), DEC;
- }
- stringOne = Stringyear + "/" + Stringmonth + "/" + Stringday + ".txt";
- if ((now.hour() < 6) || (now.hour() > 18))
- {
- atual = millis();
- if (anterior != atual)
- {
- int valor = analogRead (A0);
- val = val + valor;
- s = s + 1.00;
- if (atual - anterior >= intervalo )
- {
- anterior = atual;
- media = (val * 3.2226) / s;
- myFile = SD.open(stringOne, FILE_WRITE);
- if (myFile) {
- DateTime now = rtc.now();
- myFile.print(now.hour(), DEC);
- myFile.print(':');
- myFile.print(now.minute(), DEC);
- myFile.print(" \t");
- myFile.println(media);
- myFile.close();
- Serial.println('.');
- }
- s = 0.00;
- val = 0.00;
- }
- }
- }
- else
- {
- s = 0.00;
- val = 0.00;
- media = 0.00;
- Serial.print(".");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement