//#define SKETCH_NAME "temp_time_sd_oled";
#include "DS3231.h"
#include <DS18B20.h>
#include <SPI.h>
#include <SD.h>
File myFile;
DS3231 Clock;
boolean Century = false;
boolean PM = false;
int x = 0;
DS18B20 ds(2);
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
#define I2C_ADDRESS 0x3C
#define RST_PIN -1
SSD1306AsciiAvrI2c oled;
String newline,L1,L2,L3,L4,L5,L6,L7;
int YT_sec, YT_min, YT_hr, YT_yr, YT_mt, YT_dt;
//-----------------------------------------------------------------
void setup () {
Wire.begin();
Serial.begin(9600);
Serial.println("temp_time_sd_oled");
Serial.println("Blue,Red");
Serial.println();
#if RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0
// Call oled.setI2cClock(frequency) to change from the default frequency.
oled.setFont(Adafruit5x7);
uint32_t m = micros();
oled.clear();
oled.println("Hello world!");
}
//-----------------------------------------------------------------------------------
void loop () {
YT_sec = Clock.getSecond();
YT_min = Clock.getMinute();
YT_hr = Clock.getHour(Century, PM);
YT_yr = Clock.getYear();
YT_mt = Clock.getMonth(Century);
YT_dt = Clock.getDate();
String dt, dt_temp;
dt=String(YT_yr) + "-" + String(YT_mt) + "-" + String(YT_dt) + " " + String(YT_hr) + ":" + String(YT_min) + ":" + String(YT_sec) + ",";
dt_temp = dt;
if (!SD.begin(20)) {
Serial.println("initialization failed!");
while (1);
}
myFile = SD.open("handler.txt", FILE_WRITE);
if (myFile) {
myFile.print(dt);
} else {
Serial.println("error opening SD card file");
}
Serial.print(dt);
//-----------------------------------------------
x = 0;
while (ds.selectNext()) {
x = x + 1;
if (x > 1){
Serial.print(",");
myFile.print(",");
dt_temp = dt_temp + ",";
}
Serial.print(ds.getTempF());
myFile.print(ds.getTempF());
dt_temp = dt_temp + String(ds.getTempF());
}
//---------------------------------------------
Serial.println();
myFile.println();
myFile.close();
updateoled(dt_temp);
delay(3000);
}
//------------------------------------------------------------------------------------------
void updateoled(String newreading)
{
/*
L1=L2;
L2=L3;
L3=L4;
L4=L5;
L5=L6;
L6=L7;
L7= newreading;
display.setCursor(0,8);
display.print(L1);
display.setCursor(0,16);
display.print(L2);
display.setCursor(0,24);
display.print(L3);
display.setCursor(0,32);
display.print(L4);
display.setCursor(0,40);
display.print(L5);
display.setCursor(0,48);
display.print(L6);
display.setCursor(0,56);
display.print(L7);
*/
}
//------------------------------------------