SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Wire.h" // I2C bibliotheek
  2. #include <LiquidCrystal.h>
  3.  
  4. #define TMP102_ADDRESS 72
  5. byte degree [8] = { B00111 , B00101 , B00111 , B00000 , B00000 , B00000 , B00000 , B00000}; // Structuur van graden-symbool
  6. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  7.  
  8. void setup() {
  9.   Wire.begin(); // I2C initialiseren
  10.   lcd.begin(16, 2);
  11.   //lcd.print("Hello World!"); //Test
  12.   lcd.createChar(0, degree); //Aanmaken van eigen teken voor graden
  13. }
  14.  
  15. void loop() {
  16.   lcd.print(getTemp());
  17.   lcd.write(byte(0)); // Eigen teken voor graden
  18.   lcd.print("C");
  19.   lcd.setCursor(0,0);
  20.   delay(1000); // 1s tussen metingen
  21.  
  22. }
  23. //Methode: Berekenen temperatuur
  24. float getTemp() {
  25.   int val;
  26.   float convertedTemp;
  27.   Wire.beginTransmission(TMP102_ADDRESS);
  28.   Wire.write(0x00);
  29.   Wire.requestFrom(TMP102_ADDRESS , 2);
  30.   Wire.endTransmission();
  31.   byte MSB = Wire.read();
  32.   byte LSB = Wire.read();
  33.     val = ((MSB) << 4);  
  34.     val |= (LSB >> 4);    
  35.     convertedTemp = val*0.0625;
  36.     return convertedTemp;
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top