Recent changes
SerialPC
Creating a program
Downloading a program
Setup guide
Exporting to Code Red
Exporting to uVision
Order
tag order
From the mbed microcontroller Handbook.  

BusOut

/media/uploads/mbedofficial/digitalout_interfaces.png

The BusOut interface is used to create a number of DigitalOut pins that can be written as one value.

Hello World!

Binary counter on LEDs

#include "mbed.h"

BusOut myleds(LED1, LED2, LED3, LED4);

int main() {
    while(1) {
        for(int i=0; i<16; i++) {
            myleds = i;
            wait(0.25);
        }
    }
}

API

API summary

BusOutA digital output bus, used for setting the state of a collection of pins
Configuration Methods
BusOutCreate an BusOut, connected to the specified pins
Access Methods
writeWrite the value to the output bus
readRead the value currently output on the bus
Access Method Shorthand
operator=A shorthand for write
operator int()A shorthand for read
class BusOut : public Base
A digital output bus, used for setting the state of a collection of pins
BusOut(PinName p0,  
PinName p1 =  NC,
PinName p2 =  NC,
PinName p3 =  NC,
PinName p4 =  NC,
PinName p5 =  NC,
PinName p6 =  NC,
PinName p7 =  NC,
PinName p8 =  NC,
PinName p9 =  NC,
PinName p10 =  NC,
PinName p11 =  NC,
PinName p12 =  NC,
PinName p13 =  NC,
PinName p14 =  NC,
PinName p15 =  NC,
const char *name =  NULL)
Create an BusOut, connected to the specified pins
void write(int value)
Write the value to the output bus
int read()
Read the value currently output on the bus
BusOut& operator= (int v)
A shorthand for write
operator int()
A shorthand for read

Interface

The BusOut interface can be used on mbed pins p5-p30, and also on-board LED1-LED4

The BusOut interface can be used to set the state of the output pins, and also read back the current output state.

Examples

Scroll across the LEDs

#include "mbed.h"

BusOut myleds(LED1, LED2, LED3, LED4);

int main() {
    while(1) {
        for(int i=0; i<4; i++) {
            myleds = 1 << i;
            wait(0.25);
        }
    }
}

Related




calendar Page history
Last modified 21 Jul 2010, by   user Dan Ros   tag No tags | 4 comments      

4 comments on BusOut:

08 Jun 2011

What does the wait() do in this function? Does it clear the bus, or hold the information?

08 Jun 2011

It's just a small delay to make the led switching slow enough to be noticeable by a human.

08 Jun 2011

Thanks, and also I'm trying to debug a program. Do the pins get set in the order that they are declared in the constructor? So setting a BusOut variable like: BusOut CL(p19, p20, p18, p22); CL = 2; would make p19 store 2? CL = 3; would make p20 store 3? And so on?

09 Jun 2011

@Christopher Garner

I just commented on this very documentation deficiency in the Comments for BusIn(), and the documentation for this is even less well-specified, because you can't intuit its behavior even from the example.

Assuming that BusIn and BusOut are orthogonal, one can only assume that the following is the case (assuming active-high LEDs):

CL = 0; all LEDs off

CL = 1; a.k.a. 1<<0 or 0x1, (only) LED0 on

CL = 2; a.k.a. 1<<1 or 0x2, (only) LED1 on

CL = 4; a.k.a. 1<<2 or 0x4, (only) LED2 on

CL = 8; a.k.a. 1<<3 or 0x8, (only) LED3 on

That is, where the leftmost bits are the MSBs (most-significant bits) in the read/written "int" type, the parameters are actually passed in *reverse* order, LSB to MSB, as follows (as packed into bit positions 15..0 in an "int", respectively):

- - - - - - - - - - - - p22 p18 p20 p19

Even though the documentation isn't clear, from your example it seems like you're not "thinking binary" from your statement about p20 perhaps being "3". Each pin is a single *bit*... either a 1 or a 0. If you're not into thinking binary (yet), perhaps the following would help: http://www.arduino.cc/playground/Code/BitMath.

If it's still unclear, I'm guessing that the Forum would probably be a better place to get help.

Please login to post comments.