-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPCF8574.ino
49 lines (39 loc) · 893 Bytes
/
PCF8574.ino
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
#include "TWI.h"
#include "Driver/PCF8574.h"
// Configure: TWI bus manager
// #define USE_SOFTWARE_TWI
#if defined(USE_SOFTWARE_TWI)
#include "GPIO.h"
#include "Software/TWI.h"
Software::TWI<BOARD::D18, BOARD::D19> twi;
#else
// Configure: Hardware TWI bus clock frequency (100 or 400 kHz)
#define FREQ 100000UL
// #define FREQ 400000UL
#include "Hardware/TWI.h"
Hardware::TWI twi(FREQ);
#endif
PCF8574 port(twi, 0);
PCF8574::GPIO<0> pin(port);
void setup()
{
Serial.begin(57600);
while (!Serial);
pin.output();
}
void loop()
{
static bool state = false;
pin = state;
Serial.print(F("pin = "));
Serial.println(pin);
Serial.print(F("port.read() = "));
Serial.println(port.read(), BIN);
delay(10);
for (int i = 0; i < 16; i++)
pin = (state = !state);
delay(10);
uint8_t buf[] = { 0, 1, 0, 1, 0, 1, 0, 1 };
port.write(buf, sizeof(buf));
delay(1000);
}