티스토리 뷰

Example source code for data logger

 

#include <SD.h>

#include <Wire.h>

#include "RTClib.h"

 

#define cSDSelectionPin 10;

 

RTC_DS1307 RTC;

File hLogFile;

void setup(){

Serial.begin(9600);

 

Wire.begin();

if(!hRTC.begin()){

Serial.println("RTC is failes");

return;

}

 

pinMode(cSDSelectionPin, OUTPUT);

if(!SD.begin(cSDSelectionPin)({

Serial.println("Card failed or NOT present");

return;

}

 

char tFileName[] = "USLOG00.txt";

for(int i=0; i<100; i++){

tFileName[5] = i/10 + '0';

tFileName[6] = i%10 + '0':

if(!SD.exists(tFileName)){

hLogFile = SD.open(tFileName, FILE_WRITE);

break;

}

}

if(!hLogFile){

Serial.print("Could not create a file : ");

Serial.println(tFileName);

}

}

 

void loop(){

String theTime = h_GetTime();

h_SaveTime(theTime);

}

 

String h_GetTime(){

DateTime tNow;

tNow = hRTC.Now();

String Rst = "";

Rst = Rst + tNow.day();

 

return Rst;

}

 

void h_SaveTime(String theTime){

hLogFile.println(theTime);

}
반응형
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함