Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <Wire.h>
- LiquidCrystal lcd(12, NULL, 11, 9, 8, 7, 6);
- const int tmp102Address = 0x48;
- float temperatura;
- float temperatura2;
- byte grad[8] = {
- B01100,
- B10010,
- B10010,
- B01100,
- B00000,
- B00000,
- B00000
- };
- void setup() {
- lcd.begin(16, 2);
- lcd.noCursor();
- Wire.begin();
- Serial.begin(9600);
- lcd.createChar(0, grad);
- }
- void loop() {
- temperatura = getTemperature();
- lcd.setCursor(0, 0);
- if (temperatura >= 0) lcd.print(" ");
- else {
- lcd.print("-");
- temperatura = -temperatura;
- }
- if (temperatura < 10) lcd.print(" ");
- lcd.print(temperatura);
- Serial.println(temperatura);
- lcd.write(byte(0));
- lcd.print("C");
- lcd.setCursor(0,1);
- temperatura2 = getTemperature2();
- lcd.print(temperatura2);
- lcd.write(byte(0));
- lcd.print("C");
- delay(5000);
- }
- float getTemperature() {
- byte MSB = 0x00;
- byte LSB = 0x00;
- int TempCitita = 0;
- float TempCelsius = 0.0;
- Wire.beginTransmission(tmp102Address);
- Wire.write(0x00);
- Wire.endTransmission();
- Wire.requestFrom(tmp102Address, 2);
- Wire.endTransmission();
- MSB = Wire.read();
- LSB = Wire.read();
- //temperatura este pe 12 biti cu ultimii 4 biti 0 astfel trebuie
- //shift-ata la stanga cu 4 pozitii
- TempCitita = ((MSB << 8) | LSB) >> 4;
- TempCelsius = TempCitita * 0.0625;
- return TempCelsius;
- }
- float getTemperature2() {
- float temp = analogRead(0)*5/1024.0;
- temp = temp - 0.5;
- temp = temp / 0.01;
- // converting that reading to voltage, for 3.3v arduino use 3.3
- //float voltage = reading * 5.0;
- //voltage = voltage / 1024.0;
- //converting from 10 mv per degree wit 500 mV offset
- //to degrees ((voltage - 500mV) times 100)
- //float temperatureC = (voltage - 0.5) * 100 ;
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement