Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
12 years, 3 months ago.
How to attach a value to a ticker function?
Hi, maybe my question in the topic title isn't very precise. Let me explain what do I want to do. I'd like to send periodically (every few ms) 8 bits of data (simulating the u6050 Telefunken multiplexer). I've created a ticker, and I want to attach a value to it eg. (from bit 0 to bit 7). So,in the main function I would like to set a bunch of boolean (or maybe char (0-255) values (from bit 0 to bit 7), and then pass them periodically to the ticker function. I know what to do in the function, but for the lack of my C++ knowledge, I don't know how to pass the arguments to the ticker function. I know how to pass the arguments to a normal function thou. Any help will be very appreciated.
So for the code: (pseudo)
#include "mbed.h" Ticker u6050; void Mux_out(bool bit0, bool bit1, bool bit2, bool bit3, bool bit4, bool bit5, bool bit6, bool bit7) { // do something } int main() { u6050.attach(&Mux_out, 0.0075); // << here is the problem, how to pass the bool values to the Mux_out function while(1) {} }
I hope, that my question is clear enough.
Thank you in advance.
Regards
2 Answers
12 years, 3 months ago.
The ticker function does not support that, so unless you want to write your own ticker function you have to go for plan B: Just define a global variable (ie, where you also define ticker u6050), and write the data there in your main function. Then the ticker function can also read the same variable.
12 years, 3 months ago.
Thank you, for your quick response. I'll use the global variable.
Regards,
Gorazd Rosbach