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.
8 years, 4 months ago.
FRDM K64F: "calling" the pins in sequence
Hi everyone! :D
Another noobish question for you. Is it possible to create a loop that uses the various output pins of the board in sequence? I mean, the pin callouts for the FRDM k64f are D0, D1 and so on... If they were just integer numbers I can create a loop with a counter that uses the pins in sequence, while if they're called with the letter D in front I don't know if that's possible to do.
The evil plan is that of recreate a simple exercise in which a few LED lights will turn on in sequence, but I don't think that writing something of the type below is smart enough xD
led1 =!led1 wait(...) led2=!led2 wait(...)
[...]
led8 = !led8
Thanks in advance :)
2 Answers
8 years, 4 months ago.
Just FYI, D0, D1, etc. already map to integers. They are just not sequential :-) You could do something like this though:
uint8_t pins[8] = { D0, D1, D2, D3, D4, D5, D6, D7 }; // loop over all pins in the array for (size_t ix = 0; ix < sizeof(pins) / sizeof(pins[0]); ix++) { // toggle the pin pins[ix] = !pins[ix]; }
You need to create a DigitalOut for each pin (another array and loop) and then toggle those, rather than operating on the pin numbers themselves.
posted by 11 Aug 20168 years, 4 months ago.
You can make an array of DigitalOuts which would allow for that. However this is already done for you in BusOut, which is probably the easiest solution for you: https://developer.mbed.org/handbook/BusOut