pcf8574 ReadAll in low memory compare to single value byte

Home Forums The libraries hosted on the site PCF8574 i2c digital I/O expander pcf8574 ReadAll in low memory compare to single value byte

Viewing 1 reply thread
  • Author
    Posts
    • #11400
      Fernando

        Hello Everyone,
        I have a byte field that I need to compare with ReadAll without using low memory,
        After several attempts I couldn’t, how to compare

        PCF8574 :: DigitalInput di = pcf85741.digitalReadAll (); 
        

        with byte value?

        ex:

        
        byte valor = 220;
        if(valor == PCF8574 :: DigitalInput di = pcf85741.digitalReadAll ());
        

        Thank you

      • #11413
        Renzo Mischianti
        Keymaster

          Hi Fernando,
          you must reduce the DigitalInput object to a byte like so:

          
          byte byteValReadAll = 0;
          
          void setVal(uint8_t pin, uint8_t value){
          	if (value==HIGH){
          		byteValReadAll = byteValReadAll | bit(pin);
          	}else{
          		byteValReadAll = byteValReadAll & ~bit(pin);
          	}
          
          }
          
          [...]
          	setVal(P0, digitalInput.p0);
          	setVal(P1, digitalInput.p1);
          	setVal(P2, digitalInput.p2);
          	setVal(P3, digitalInput.p3);
          	setVal(P4, digitalInput.p4);
          	setVal(P5, digitalInput.p5);
          	setVal(P6, digitalInput.p6);
          	setVal(P7, digitalInput.p7);
          	
          	Serial.println(byteValReadAll, BIN);
          [...]
          
          

          Bye Renzo

      Viewing 1 reply thread
      • You must be logged in to reply to this topic.
      Exit mobile version