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.
11 years, 9 months ago.
flasher with a hardwired pin
I would like to set up a class for a specific hardware item that is connected to the mbed with specific pins. So the pins are fixed for the class to specific values. The method below using pointers actually works ... but is there a way to set the pin value without using the "new" operator or adding default construtor as in the example?
#include "mbed.h" //test setting up an mbed pin as a class member initialized in the constructor class flasher { public: DigitalOut* DO1; DigitalOut* DO2; flasher() { DO1 = new DigitalOut(LED1); DO2 = new DigitalOut(LED2);} //establish LED1 to flash void flash(void) { *DO1 = 1; wait(0.25); *DO1 = 0; wait(0.25); *DO2 = 0; wait(0.25); *DO2 = 1; wait(0.25); } }; int main() { flasher ff; while(1) { ff.flash(); wait(0.25); } }
Question relating to:
1 Answer
11 years, 9 months ago.
Hi James,
Is this what you are looking for?
It uses the C++ initialisation list syntax.
Hope that helps,
Simon
Just as a note, if you had published your program and embedded that in your question to show your problem, I could have just clicked "import" to recreate your existing code in my compiler workspace, done my changes, then "publish", which would have been even easier for me to help you :)
posted by Simon Ford 21 Feb 2013