Hi Clemens,
For my touchpad project I need to alternate the function of some pins between an analog input and a digital output. To do this I probably have to access the registers directly as I don't see how to do this using AnalogIn & DigitalOut (dynamic pin allocation?).
The natural way in C++ is to dynamically create objects, either as local variables or using new/delete.
As an example using local variables (i.e. allocated on the stack), see:
http://mbed.org/users/simon/published/aadb7ad83d46450b9ea13e1c1282456d/AnalogInDigitalOut.zip
which basically does:
float do_something_analog() {
AnalogIn x(p20);
return x.read();
}
void do_something_digital() {
DigitalOut x(p20);
x = 1;
wait(0.5);
x = 0;
}
The constructor of objects (when you define e.g. AnalogIn) sets things up. The alternative would be to allocate on the heap using new/delete and pointers to the objects.
Not sure if this is ideal, but it should be enough to get you going. We can learn from there...
Simon
Hi,
For my touchpad project I need to alternate the function of some pins between an analog input and a digital output. To do this I probably have to access the registers directly as I don't see how to do this using AnalogIn & DigitalOut (dynamic pin allocation?). The register names from the datasheet are not recognised by the compiler. Is there an "mbed way" to do this? Or am I supposed to provide my own definitions? Or is there an other way to achieve this? I don't want to use more pins.
Regards,
Clemens