-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
PCF8575.h
93 lines (63 loc) · 2.07 KB
/
PCF8575.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#pragma once
//
// FILE: PCF8575.h
// AUTHOR: Rob Tillaart
// DATE: 2020-07-20
// VERSION: 0.2.3
// PURPOSE: Arduino library for PCF8575 - 16 channel I2C IO expander
// URL: https://github.com/RobTillaart/PCF8575
#include "Arduino.h"
#include "Wire.h"
#define PCF8575_LIB_VERSION (F("0.2.3"))
#ifndef PCF8575_INITIAL_VALUE
#define PCF8575_INITIAL_VALUE 0xFFFF
#endif
#define PCF8575_OK 0x00
#define PCF8575_PIN_ERROR 0x81
#define PCF8575_I2C_ERROR 0x82
class PCF8575
{
public:
// deviceAddress base = 0x20 + depends on address bits
explicit PCF8575(const uint8_t deviceAddress = 0x20, TwoWire *wire = &Wire);
bool begin(uint16_t value = PCF8575_INITIAL_VALUE);
bool isConnected();
// note: setting the address may corrupt internal buffer values
// and should not be used unless it is needed.
// a read16() / write16() call updates them.
bool setAddress(const uint8_t deviceAddress);
uint8_t getAddress();
uint16_t read16();
uint8_t read(uint8_t pin);
uint16_t value();
void write16(const uint16_t value);
void write(const uint8_t pin, const uint8_t value);
uint16_t valueOut();
// added 0.1.07/08 Septillion
uint16_t readButton16();
uint16_t readButton16(const uint16_t mask);
uint8_t readButton(const uint8_t pin);
void setButtonMask(uint16_t mask);
uint16_t getButtonMask();
// rotate, shift, toggle, reverse expect all lines are output
void toggle(const uint8_t pin);
void toggleMask(const uint16_t mask = 0xFFFF); // 0xFFFF == invertAll()
void shiftRight(const uint8_t n = 1);
void shiftLeft(const uint8_t n = 1);
void rotateRight(const uint8_t n = 1);
void rotateLeft(const uint8_t n = 1);
void reverse();
void select(const uint8_t pin);
void selectN(const uint8_t pin);
void selectNone();
void selectAll();
int lastError();
private:
uint8_t _address;
uint16_t _dataIn;
uint16_t _dataOut;
uint16_t _buttonMask;
int _error;
TwoWire* _wire;
};
// -- END OF FILE --