Facebook
From Cream Lizard, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 209
  1. #include "Wire.h"
  2. #define SENSOR_ADDRESS 0x68
  3. #define TEMP_INT_POINTER 0x11
  4. #define TEMP_DEC_POINTER 0x12
  5. #define TEMP_READ_FAIL 0xFF
  6. #define LATCH_DIO 4
  7. #define CLK_DIO 7
  8. #define DATA_DIO 8
  9.  
  10. const byte leterE = B10000110;
  11.  
  12. const byte num0 = B11000000;
  13. const byte num1 = B11111001;
  14. const byte num2 = B10100100;
  15. const byte num3 = B10110000;
  16. const byte num4 = B10011001;
  17. const byte num5 = B10010010;
  18. const byte num6 = B10000010;
  19. const byte num7 = B11111000;
  20. const byte num8 = B10000000;
  21. const byte num9 = B10010000;
  22. const byte nums[]= {num0,num1,num2,num3,num4,num5,num6,num7,num8,num9};
  23.  
  24.  
  25. const byte point1 = B00000001;
  26. const byte point2 = B00000010;
  27. const byte point3 = B00000100;
  28. const byte dot = B01111111;
  29. void setup()
  30. {
  31.   pinMode(LATCH_DIO,OUTPUT);
  32.   pinMode(CLK_DIO,OUTPUT);
  33.   pinMode(DATA_DIO,OUTPUT);
  34.   Wire.begin();
  35.   Serial.begin(9600);
  36. }
  37. void loop()
  38. {
  39.   displayTemperature();
  40.  
  41. }
  42.  
  43. void displayTemperature()
  44. {   byte data = TEMP_READ_FAIL;
  45.   Wire.beginTransmission(SENSOR_ADDRESS);
  46.   Wire.write(TEMP_INT_POINTER); // the integer portion
  47.   Wire.endTransmission();
  48.  
  49.   Wire.requestFrom(SENSOR_ADDRESS, 1);
  50.   if (Wire.available()) {
  51.     data = Wire.read();
  52.   displayNow(nums[data%10],point2);
  53.   data=data-data%10;
  54.   displayNow(nums[(data%100)/10],point1);
  55.   }
  56.   else{
  57.   displayNow(dot, point3);
  58.   }
  59. }
  60. void displayNow(byte x, byte y){
  61.  digitalWrite(LATCH_DIO,LOW);
  62.   shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, x);
  63.   shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, y );
  64.   digitalWrite(LATCH_DIO,HIGH);  
  65. }
  66.  
  67.