mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#pragma once
|
|
//
|
|
// FILE: DS18B20.h
|
|
// AUTHOR: Rob.Tillaart@gmail.com
|
|
// VERSION: 0.1.10
|
|
// DATE: 2017-07-25
|
|
// PUPROSE: library for DS18B20 temperature sensor with minimal footprint
|
|
//
|
|
|
|
//
|
|
// BOTTOM VIEW
|
|
//
|
|
// PIN MEANING
|
|
// /---+
|
|
// / o | 1 GND
|
|
// | o | 2 DATA
|
|
// \ o | 3 VCC
|
|
// \---+
|
|
//
|
|
|
|
#define DS18B20_LIB_VERSION (F("0.1.10"))
|
|
|
|
#include <OneWire.h>
|
|
|
|
// Error Code
|
|
#define DEVICE_DISCONNECTED -127
|
|
#define DEVICE_CRC_ERROR -128
|
|
|
|
// config codes
|
|
#define DS18B20_CLEAR 0x00
|
|
#define DS18B20_CRC 0x01
|
|
|
|
|
|
typedef uint8_t DeviceAddress[8];
|
|
typedef uint8_t ScratchPad[9];
|
|
|
|
|
|
class DS18B20
|
|
{
|
|
public:
|
|
explicit DS18B20(OneWire *);
|
|
bool begin(uint8_t retries = 3);
|
|
void setResolution(uint8_t newResolution = 9);
|
|
void requestTemperatures(void);
|
|
float getTempC(void);
|
|
bool isConversionComplete(void);
|
|
bool getAddress(uint8_t* buf);
|
|
|
|
void setConfig(uint8_t config) { _config = config; };
|
|
uint8_t getConfig() { return _config; };
|
|
|
|
private:
|
|
void readScratchPad(uint8_t *, uint8_t);
|
|
DeviceAddress _deviceAddress;
|
|
OneWire* _wire;
|
|
bool _addresFound;
|
|
uint8_t _config;
|
|
};
|
|
|
|
// -- END OF FILE --
|