xreef/PCF8574_library

Changing Output to Input mid program

alphaomega16 opened this issue · 1 comments

Attempting to change Output to Input. Pin will not become Input even after executing PCF8574.begin(); during subroutine. Pin gets stuck in a HIGH state.

Changing from an Input to and Output does work.

The goal is to have the ability to read a pin and change its state at different times in the program.
Sample program to test:

#include "Arduino.h"
#include "PCF8574.h"

// Set  the i2c HEX address
  PCF8574 pcf1(0x20);
  PCF8574 pcf2(0x21);
  unsigned long timeElapsed;
  //byte by;
  int P1P1;
  int P1P2;
  int P2P1;
  int P2P2;
  int mode;
  int i;
  //PCF8574::DigitalInput di;

void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200);
    delay(1000);

  //Set pinmodes
  //pcf1.pinMode(P7, INPUT); //Trigger Pin
  //pcf1.pinMode(P6, INPUT);  //Test Board Output Pin
  //pcf1.pinMode(P5, INPUT);
  //pcf1.pinMode(P4, INPUT);  //SW4
  //pcf1.pinMode(P3, INPUT);  //SW3
  pcf1.pinMode(P2, INPUT);  //SW2
  //pcf1.pinMode(P1, INPUT);  //SW1
  //pcf1.pinMode(P0, INPUT);  //SW0
  //pinMode(2, INPUT);


  //pcf2.pinMode(P0, OUTPUT);
  pcf2.pinMode(P1, OUTPUT);
  pcf2.pinMode(P2, OUTPUT);
  //pcf2.pinMode(P3, OUTPUT);
  //pcf2.pinMode(P4, OUTPUT);
  //pcf2.pinMode(P5, OUTPUT);
  //pcf2.pinMode(P6, OUTPUT);
  //pcf2.pinMode(P7, OUTPUT);

    Serial.print("Init pcf1...");
    if (pcf1.begin()){
	    Serial.println("OK");
    }else{
	    Serial.println("KO");
    }
    Serial.print("Init pcf2...");
    if (pcf2.begin()){
	    Serial.println("OK");
    }else{
	    Serial.println("KO");
    }

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(30);
  Serial.print(P1P1);
  Serial.println(" P1P1 HIGH");
  Serial.print(P1P2);
  Serial.println(" P1P2 HIGH");
  Serial.print(P2P1);
  Serial.println(" P2P1 HIGH");
  Serial.print(P2P2);
  Serial.println(" P2P2 HIGH");
  pcf2.digitalWrite(P2, LOW);
  if (mode == 0){
  pcf2.digitalWrite(P1, LOW);
  };
  delay(30);
    P1P1 = pcf1.digitalRead(1);
    P1P2 = pcf1.digitalRead(2);
    P2P1 = pcf2.digitalRead(1);
    P2P2 = pcf2.digitalRead(2);
  delay(1000);
  Serial.print(P1P1);
  Serial.println(" P1P1 LOW");
  Serial.print(P1P2);
  Serial.println(" P1P2 LOW");
  Serial.print(P2P1);
  Serial.println(" P2P1 LOW");
  Serial.print(P2P2);
  Serial.println(" P2P2 LOW");
  pcf2.digitalWrite(P2, HIGH);
    if (mode == 0){
  pcf2.digitalWrite(P1, HIGH);
    };
  delay(30);
    P1P1 = pcf1.digitalRead(1);
    P1P2 = pcf1.digitalRead(2);
    P2P1 = pcf2.digitalRead(1);
    P2P2 = pcf2.digitalRead(2);
  delay(1000);
    if (i >= 5) {
    pcf2.pinMode(P1, INPUT);
    pcf2.begin(0x21);
    
    //pcf2.digitalWrite(P1, LOW);
    mode = 1;
    }
    Serial.println(i);
    i++;

  Serial.println(mode);
  delay(1000);
}

Hi,
sorry for the late response, but that situation hasn't been tested and implemented.
Bye Renzo