I am stuck again. Take a look at the code below and please tell me why I can't get the testClick function to print "6". I have spent 2 days trying to work this out, looking at various resources online. I just can't work it out.
I have simplified a class I am writing and a class I am extending in the code below. I think the problem I am having is with the referencing / de-referencing of pointers.
What I get is:
Which looks like memory addresses, I expect (want) to see the integer "6" printed to serial.
Background, I am extending the OneButton library (https://github.com/mathertel/OneButton) to suite my purposes of debouncing I/O expander and I'm trying to get my callback functions working (these will eventually generate CANbus messages from debounced button pushes on the I/O expander. The callback function must fit the typedef in the base OneButton library:
hence my class method which takes a void* as a parameter. I need a way to get to the value of the void pointer passed in.
I have simplified a class I am writing and a class I am extending in the code below. I think the problem I am having is with the referencing / de-referencing of pointers.
Code:
void testClick(void *id) {
Serial.println( (int) id, DEC);
Serial.println( (int) &id, DEC);
}
void setup() {
Serial.begin(9600);
Serial.println("start");
int *buttonIdPtr;
int buttonId = 6;
buttonIdPtr = &buttonId;
testClick(buttonIdPtr);
}
void loop() {
}
What I get is:
Code:
start
537362412
537362388
Which looks like memory addresses, I expect (want) to see the integer "6" printed to serial.
Background, I am extending the OneButton library (https://github.com/mathertel/OneButton) to suite my purposes of debouncing I/O expander and I'm trying to get my callback functions working (these will eventually generate CANbus messages from debounced button pushes on the I/O expander. The callback function must fit the typedef in the base OneButton library:
Code:
typedef void (*parameterizedCallbackFunction)(void*);
hence my class method which takes a void* as a parameter. I need a way to get to the value of the void pointer passed in.
Last edited: