#include <Wire.h>
#include <DS3231-RTC.h>
RTClib myRTC;
//byte data1;
//byte data2;
uint16_t data_combined;
void setup () {
Serial.begin(9600);
Wire.begin();
delay(500);
Serial.println("Nano Ready!");
}
void loop () {
delay(1000);
DateTime now = myRTC.now();
Serial.print(now.getYear(), DEC);
Serial.print('/');
Serial.print(now.getMonth(), DEC);
Serial.print('/');
Serial.print(now.getDay(), DEC);
Serial.print(' ');
Serial.print(now.getHour(), DEC);
Serial.print(':');
Serial.print(now.getMinute(), DEC);
Serial.print(':');
Serial.print(now.getSecond(), DEC);
Serial.print(' ');
Serial.print(now.getDay() );
Serial.print(' ');
Wire.beginTransmission(0x68);
Wire.write(0x11);
Wire.endTransmission();
Wire.requestFrom(0x68, 2);
//float temp= (Wire.read()<<2 | (Wire.read()&0b11000000)>>6)*0.25;
// float temp= (Wire.read()<<8 | Wire.read()>>6)*0.25;
//float temp= (Wire.read());
//Serial.print(Wire.read() , BIN); Serial.print(' ');
//Serial.println(temp);
byte data1 = Wire.read(); // so I just save both bytes separately here.
byte data2 = Wire.read();
float temp= (data1<<2 | data2>>6)*0.25;
data_combined = word(data1,data2);
Serial.print("temp := ");
Serial.print(data1, DEC);
Serial.print(" |First byte : ");
Serial.print(data1,BIN);
Serial.print(" | << : ");
Serial.print(data1<<2,BIN);
Serial.print(" | Second byte : ");
Serial.print(data2,BIN);
Serial.print(" | >> : ");
Serial.print(data2>>6,BIN);
Serial.print(" | TEMP : ");
if (data1 & 0b10000000)
{
Serial.print("-");
temp=256-temp;
}
else Serial.print("+");
Serial.print(temp);
Serial.print(" | Combined to make: ");
Serial.println(data_combined,BIN);
Serial.println("---");
}