#include "Wire.h" #define SENSOR_ADDRESS 0x68 #define TEMP_INT_POINTER 0x11 #define TEMP_DEC_POINTER 0x12 #define TEMP_READ_FAIL 0xFF #define LATCH_DIO 4 #define CLK_DIO 7 #define DATA_DIO 8 const byte leterE = B10000110; const byte num0 = B11000000; const byte num1 = B11111001; const byte num2 = B10100100; const byte num3 = B10110000; const byte num4 = B10011001; const byte num5 = B10010010; const byte num6 = B10000010; const byte num7 = B11111000; const byte num8 = B10000000; const byte num9 = B10010000; const byte nums[]= {num0,num1,num2,num3,num4,num5,num6,num7,num8,num9}; const byte point1 = B00000001; const byte point2 = B00000010; const byte point3 = B00000100; const byte dot = B01111111; void setup() { pinMode(LATCH_DIO,OUTPUT); pinMode(CLK_DIO,OUTPUT); pinMode(DATA_DIO,OUTPUT); Wire.begin(); Serial.begin(9600); } void loop() { displayTemperature(); } void displayTemperature() { byte data = TEMP_READ_FAIL; Wire.beginTransmission(SENSOR_ADDRESS); Wire.write(TEMP_INT_POINTER); // the integer portion Wire.endTransmission(); Wire.requestFrom(SENSOR_ADDRESS, 1); if (Wire.available()) { data = Wire.read(); displayNow(nums[data%10],point2); data=data-data%10; displayNow(nums[(data%100)/10],point1); } else{ displayNow(dot, point3); } } void displayNow(byte x, byte y){ digitalWrite(LATCH_DIO,LOW); shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, x); shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, y ); digitalWrite(LATCH_DIO,HIGH); }