I am useing port 2 on my DIY wiring board as a bi directional port (bus) and works fine accessing it using a sketch such as below. (port 1 is used as the chip /latch select)
// function getiptbyte gets the data byte on the input latch
byte getiptbyte (){
portMode(2, INPUT); // flips the bus port to input
portWrite(1, 0x80); // sets the latch for the input buffer
ipt = portRead (2); // reads the data on the buss port
portWrite(1, 0x00); // turns off the input latch
portMode(2, OUTPUT); // resets the bus port to output
return ipt;
}
However when I try to move this into a class library (As below) it does not read the data on the bus for some reason. Is this the correct way to manipulate the portmode in a libary? and is there any example librarys with a port being used as Bi-directional?
// member: getiptbyte gets the data byte on the input latch
byte iWire::getiptbyte (){
portMode(2, INPUT); // flips the bus port to input
portWrite(1, 0x80); // sets the latch for the input buffer
ipt = portRead (2); // reads the data on the buss port
portWrite(1, 0x00); // turns off the input latch
portMode(2, OUTPUT); // resets the bus port to output
// ipt = (0xAA); // Used only to test that the return works.
return ipt;
}
Thanks Zap.