Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <Wire.h>
  3.  
  4. LiquidCrystal lcd(12, NULL, 11, 9, 8, 7, 6);
  5.  
  6. const int tmp102Address = 0x48;
  7. float temperatura;
  8. float temperatura2;
  9.  
  10. byte grad[8] = {
  11. B01100,
  12. B10010,
  13. B10010,
  14. B01100,
  15. B00000,
  16. B00000,
  17. B00000
  18. };
  19. void setup() {
  20. lcd.begin(16, 2);
  21. lcd.noCursor();
  22. Wire.begin();
  23. Serial.begin(9600);
  24. lcd.createChar(0, grad);
  25. }
  26.  
  27. void loop() {
  28. temperatura = getTemperature();
  29. lcd.setCursor(0, 0);
  30. if (temperatura >= 0) lcd.print(" ");
  31. else {
  32. lcd.print("-");
  33. temperatura = -temperatura;
  34. }
  35. if (temperatura < 10) lcd.print(" ");
  36. lcd.print(temperatura);
  37. Serial.println(temperatura);
  38. lcd.write(byte(0));
  39. lcd.print("C");
  40. lcd.setCursor(0,1);
  41. temperatura2 = getTemperature2();
  42. lcd.print(temperatura2);
  43. lcd.write(byte(0));
  44. lcd.print("C");
  45. delay(5000);
  46. }
  47.  
  48. float getTemperature() {
  49. byte MSB = 0x00;
  50. byte LSB = 0x00;
  51. int TempCitita = 0;
  52. float TempCelsius = 0.0;
  53. Wire.beginTransmission(tmp102Address);
  54. Wire.write(0x00);
  55. Wire.endTransmission();
  56. Wire.requestFrom(tmp102Address, 2);
  57. Wire.endTransmission();
  58. MSB = Wire.read();
  59. LSB = Wire.read();
  60. //temperatura este pe 12 biti cu ultimii 4 biti 0 astfel trebuie
  61. //shift-ata la stanga cu 4 pozitii
  62. TempCitita = ((MSB << 8) | LSB) >> 4;
  63. TempCelsius = TempCitita * 0.0625;
  64. return TempCelsius;
  65. }
  66.  
  67. float getTemperature2() {
  68. float temp = analogRead(0)*5/1024.0;
  69. temp = temp - 0.5;
  70. temp = temp / 0.01;
  71. // converting that reading to voltage, for 3.3v arduino use 3.3
  72. //float voltage = reading * 5.0;
  73. //voltage = voltage / 1024.0;
  74.  
  75.  
  76. //converting from 10 mv per degree wit 500 mV offset
  77. //to degrees ((voltage - 500mV) times 100)
  78. //float temperatureC = (voltage - 0.5) * 100 ;
  79.  
  80. return temp;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement