#include <Wire.h>
#define ADDRESS 0x8
#define TEMP_TYPE 1
void requestEvent();
void receiveEvent();
byte temp = 24;
byte unitType = 0;
void setup() {
// put your setup code here, to run once:
Wire.begin(ADDRESS);
Wire.onReceive(receiveEvent);
Wire.onRequest(requestEvent);
}
void loop() {
// put your main code here, to run repeatedly:
}
void receiveEvent(int howmany)
{
String cmd = "";
//UNIT0 -5 byte
while(1 < Wire.available())
{
char c = Wire.read();
cmd.concat(c);
}
Serial.println(cmd);
if(cmd == "UNIT") unitType = Wire.read();
cmd = "";
}
void requestEvent()
{
switch(unitType)
{
case 0:
Wire.write(temp);
break;
case 1:
Wire.write(byte((temp*1.8) + 32));
break;
default:
break;
}
}