This is a simple code to turn LED on and off by using PCF8574, the code works as expected, but I want to pass the 'Address' which is 0x27 to object declaration part to let user change it at any time cause address may change according to the chip number(PCF8574AT, PCF8574T).
it did not work, I have to hard code the address like this:
B4X:
PCF8574 pcf(&I2Ctwo, b4r_stn::_i2caddress); // did not work, how can I pass address to this line?
it did not work, I have to hard code the address like this:
B4X:
PCF8574 pcf(&I2Ctwo, 0x27); //works OK, address is hard codded
Main:
Sub Process_Globals
Public Serial1 As Serial
End Sub
Private Sub AppStart
STN.Begin(21,22,0x27) 'pass SDA, SCL and address to STN module
End Sub
STN module:
Sub Process_Globals
Private SDApin As Byte
Private SCLpin As Byte
Private I2Caddress As Byte
End Sub
public Sub Begin(SDAp As Byte, SCLp As Byte, Address As Byte)
SDApin = SDAp
SCLpin = SCLp
I2Caddress = Address
RunNative("pcfsetup",Null)
Delay(200)
RunNative("play",Null)
End Sub
#IF C
#include <PCF8574.h>
// Instantiate Wire for generic use at 400kHz
TwoWire I2Cone = TwoWire(0);
// Instantiate Wire for generic use at 100kHz
TwoWire I2Ctwo = TwoWire(1);
//PCF8574 pcf(&I2Ctwo, b4r_stn::_i2caddress); // did not work, how can I pass address to this line?
PCF8574 pcf(&I2Ctwo, 0x27); //works OK, address is hard codded
void pcfsetup(B4R::Object* o) {
I2Ctwo.begin(b4r_stn::_sdapin, b4r_stn::_sclpin,100000U); // SDA pin, SCL pin, 100kHz frequency
pcf.pinMode(P0, OUTPUT);
bool b = pcf.begin();
}
void play(B4R::Object* o)
{
pcf.digitalWrite(P0, HIGH);
delay(2000);
pcf.digitalWrite(P0, LOW);
}
#End If