GY-63_MS5611/libraries/PCF8591/PCF8591.h

77 lines
1.7 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: PCF8591.h
// AUTHOR: Rob Tillaart
// DATE: 2020-03-12
2022-11-21 15:33:51 -05:00
// VERSION: 0.1.3
2021-01-29 06:31:58 -05:00
// PURPOSE: I2C PCF8591 library for Arduino
// URL: https://github.com/RobTillaart/PCF8591
#include "Arduino.h"
#include "Wire.h"
2022-11-21 15:33:51 -05:00
#define PCF8591_LIB_VERSION (F("0.1.3"))
2021-01-29 06:31:58 -05:00
2021-12-23 08:26:13 -05:00
#define PCF8591_OK 0x00
#define PCF8591_PIN_ERROR 0x81
#define PCF8591_I2C_ERROR 0x82
#define PCF8591_MODE_ERROR 0x83
#define PCF8591_CHANNEL_ERROR 0x84
#define PCF8591_ADDRESS_ERROR 0x85
2021-01-29 06:31:58 -05:00
class PCF8591
{
public:
explicit PCF8591(const uint8_t address = 0x48, TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32)
2021-12-23 08:26:13 -05:00
bool begin(uint8_t sda, uint8_t scl, uint8_t value = 0);
2021-01-29 06:31:58 -05:00
#endif
2021-12-23 08:26:13 -05:00
bool begin(uint8_t value = 0);
2021-01-29 06:31:58 -05:00
bool isConnected();
2022-11-21 15:33:51 -05:00
// ADC PART
// auto increment not tested ==> use with care!
void enableINCR();
void disableINCR();
bool isINCREnabled();
// analogRead() returns the value.
uint8_t analogRead(uint8_t channel, uint8_t mode = 0);
// analogRead4() returns PCF8591_OK or an error code.
uint8_t analogRead4();
// access the 4 channels read with analogRead4()
uint8_t lastRead(uint8_t channel);
2021-01-29 06:31:58 -05:00
2022-11-21 15:33:51 -05:00
// DAC PART
void enableDAC();
void disableDAC();
bool isDACEnabled();
2021-01-29 06:31:58 -05:00
2022-11-21 15:33:51 -05:00
bool analogWrite(uint8_t value = 0); // returns true on success.
uint8_t lastWrite(); // returns last successful write
2021-01-29 06:31:58 -05:00
2022-11-21 15:33:51 -05:00
// ERROR HANDLING
2021-01-29 06:31:58 -05:00
int lastError();
2021-12-23 08:26:13 -05:00
2021-01-29 06:31:58 -05:00
private:
uint8_t _address;
uint8_t _control;
uint8_t _dac;
uint8_t _adc[4];
int _error;
2021-12-23 08:26:13 -05:00
2021-01-29 06:31:58 -05:00
TwoWire* _wire;
};
2021-12-23 08:26:13 -05:00
2022-11-21 15:33:51 -05:00
// -- END OF FILE --
2021-12-23 08:26:13 -05:00