Last active
February 2, 2020 21:57
-
-
Save ti-nspire/d6c477961fe8fb71c9480f1c4e261737 to your computer and use it in GitHub Desktop.
LM75_library_for_ATmega328P
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "LM75.h" | |
float LM75::getTemp(){ | |
int16_t tempData; | |
myI2C.start(); | |
myI2C.send(_ADDRESS_W); | |
myI2C.send(TEMP_REGISTER); | |
myI2C.start(); | |
myI2C.send(_ADDRESS_R); | |
tempData = (int16_t)myI2C.readACK() << 8; | |
tempData |= myI2C.readNACK(); | |
myI2C.stop(); | |
return (float)tempData / 256.0; | |
} | |
unsigned char LM75::getAddressA210(){ | |
return _ADDRESS_A210; | |
} | |
// コンストラクタ | |
LM75::LM75(uint8_t addressA210){ | |
_ADDRESS_A210 = addressA210; | |
_ADDRESS_W = ADDRESS_FIXED | (_ADDRESS_A210 << 1); | |
_ADDRESS_R = _ADDRESS_W | 1; | |
} | |
LM75::LM75(){ | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <inttypes.h> | |
#include "myI2C.h" | |
#ifndef LM75_H | |
#define LM75_H | |
#define ADDRESS_FIXED 0b10010000 | |
#define TEMP_REGISTER 0b00000000 // 温度を読み出すときはポインタレジスタにこの値を書き込む。 | |
class LM75{ | |
private: | |
uint8_t _ADDRESS_A210; // スレーブアドレスのユーザー定義部分(0~7) | |
uint8_t _ADDRESS_W; // 書き込み通知用のアドレス | |
uint8_t _ADDRESS_R; // 読み出し通知用のアドレス | |
public: | |
float getTemp(); | |
uint8_t getAddressA210(); | |
// コンストラクタ | |
LM75(uint8_t addressA210); | |
LM75(); | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment