I'm not 100% sure (don't have a touch screen to test), but the following approach might work:
class NdsTouchScreen
{
DigitalInOut _bottom, _left, _top, _right;
PinName _bottomPin, _leftPin, _topPin, _rightPin;
public:
NdsTouchScreen(PinName bottom, PinName left, PinName top, PinName right)
: _bottom(bottom), _left(left), _top(top), _right(right),
_bottomPin(bottom), _leftPin(left), _topPin(top), _rightPin(right)
{};
float readX()
{
// apply 0-Vcc to top-bottom pair
_top.output();
_top = 0;
_bottom.output();
_bottom = 1;
// set left and right to input mode
_left.input();
_right.input();
// wait a bit
wait_ms(10);
// return analog value of left as X
return AnalogIn(_leftPin).read();
}
float readY()
{
// apply 0-Vcc to left-right pair
_left.output();
_left = 0;
_right.output();
_right = 1;
// set top and bottom to input mode
_top.input();
_bottom.input();
// wait a bit
wait_ms(10);
// return analog value of top as Y
return AnalogIn(_topPin).read();
}
};
NdsTouchScreen s(p9, p10, p11, p12);
DigitaIn and DigitalOut are great, but I need to implement a bidirectional IO pin.
I would expect an API with methods like those:
What is the MBED way of doing it?