digitalWrite equivilent

24 Jun 2010

I'm porting a program from the Arduino to the mbed... Arduino has a function called digitalWrite and is called like:

digitalWrite(pin,HIGH/LOW);

This is actually very convenient when writing out data to multiple pins inside a loop.

Is there a way I can address a DigitalOut pin in code by pin# like this rather than by a given pin name?

thanks

24 Jun 2010

Two solutions come to mind.

1. Use a BusOut or PortOut to set multiple pins at once.
2. Make an array of DigitalOut instances.

24 Jun 2010 . Edited: 24 Jun 2010

BusOut looks handy.. but would you be so kind to give an example of how you'd create an array of DigitalOut's?

24 Jun 2010

Something like this:

DigitalOut mypins[] = {p5, p6, p7};

24 Jun 2010

Igor,

That worked perfectly! Just what I was looking for. Thanks!!!!!!!