Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Arduino.h"
- #include "PCF8574.h"
- // Set i2c address
- PCF8574 pcf1(0x20);
- PCF8574 pcf2(0x21);
- PCF8574 pcf3(0x22);
- unsigned long cur_time, old_time;
- bool stateLed = 0;
- byte pin_led = 5;
- byte pin_pcf[] = {0, 1, 2, 3, 4, 5, 6, 7};
- byte dt_pcf1[10];
- byte dt_pcf2[10];
- byte dt_pcf3[10];
- void setup() {
- // put your setup code here, to run once:
- delay(100);
- Serial.begin(115200);
- pinMode(pin_led, OUTPUT);
- Serial.print("Init pcf8574...");
- for (int i = 0; i < sizeof(pin_pcf); i++) {
- Serial.print(i); Serial.print(",");
- pcf1.pinMode(pin_pcf[i], INPUT);
- pcf2.pinMode(pin_pcf[i], INPUT);
- pcf3.pinMode(pin_pcf[i], INPUT);
- }
- Serial.println();
- if (pcf1.begin()) {
- Serial.println("pcf1 OK");
- } else {
- Serial.println("pcf1 NOK");
- }
- if (pcf2.begin()) {
- Serial.println("pcf2 OK");
- } else {
- Serial.println("pcf2 NOK");
- }
- if (pcf3.begin()) {
- Serial.println("pcf3 OK");
- } else {
- Serial.println("pcf3 NOK");
- }
- delay(100);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- cur_time = millis();
- if (cur_time - old_time >= 500) {
- stateLed = !stateLed;
- digitalWrite(pin_led, stateLed);
- Serial.print("pcf1: ");
- for (int i = 0; i < sizeof(pin_pcf); i++) {
- Serial.print(pcf1.digitalRead(pin_pcf[i]));
- Serial.print(",");
- delay(5);
- }
- Serial.println();
- Serial.print("pcf2: ");
- for (int i = 0; i < sizeof(pin_pcf); i++) {
- Serial.print(pcf2.digitalRead(pin_pcf[i]));
- Serial.print(",");
- delay(5);
- }
- Serial.println();
- Serial.print("pcf3: ");
- for (int i = 0; i < sizeof(pin_pcf); i++) {
- Serial.print(pcf3.digitalRead(pin_pcf[i]));
- Serial.print(",");
- delay(5);
- }
- Serial.println();
- Serial.println();
- old_time = cur_time;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement