Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <Wire.h>
- const unsigned char ADDR = 0b1001000;
- unsigned char integer = 0;
- void read_temp(int address);
- unsigned char lowValue = 0, highValue = 0;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- Wire.begin();
- }
- void loop() {
- delay(1000);
- read_temp(ADDR);
- // Serial.print(F("Raw value: ")); Serial.print(highValue); Serial.print(F(" ")); Serial.println(lowValue);
- if (highValue & 0b10000000)
- {
- Serial.print(F("-"));
- integer = highValue & 0b01111111;
- integer = highValue ^ 0xFF;
- integer += 1;
- }
- else
- {
- integer = highValue;
- }
- Serial.print(integer);
- if (lowValue & 0b10000000)
- {
- Serial.print(F(".5"));
- }
- Serial.println("");
- }
- void read_temp(int address)
- {
- //start the communication with IC with the address xx
- Wire.beginTransmission(address);
- //send a bit and ask for register zero
- Wire.write(0);
- //end transmission
- Wire.endTransmission();
- //request 1 byte from address xx
- Wire.requestFrom(address, 2);
- //wait for response
- while (Wire.available() == 0);
- //put the temperature in variable c
- highValue = Wire.read();
- lowValue = Wire.read();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement