BusOut Hello World

Fork of BusOut_HelloWorld by Mbed

Use

The BusOut interface can be used to create an artificial bus of pins out of any digital ins. The pins do not have to have sequential hardware addressing. This example program counts up from 0 to 15 or binary 0000 to 1111 . The effect of this is turning LED1-LED4 on or off according to the number going across the bus. The example code toggles LED's on / off, if a tricolor led is on the board then the led will change colors.

IntegerbinaryLED On(1) / Off(0)
00000LED4=0 LED3=0 LED2=0 LED1=0
10001LED4=0 LED3=0 LED2=0 LED1=1
20010LED4=0 LED3=0 LED2=1 LED1=0
30011LED4=0 LED3=0 LED2=1 LED1=1
40100LED4=0 LED3=1 LED2=0 LED1=0
50101LED4=0 LED3=1 LED2=0 LED1=1
60110LED4=0 LED3=1 LED2=1 LED1=0
70111LED4=0 LED3=1 LED2=1 LED1=1
81000LED4=1 LED3=0 LED2=0 LED1=0
91001LED4=1 LED3=0 LED2=0 LED1=1
101010LED4=1 LED3=0 LED2=1 LED1=0
111011LED4=1 LED3=0 LED2=1 LED1=1
121100LED4=1 LED3=1 LED2=0 LED1=0
131101LED4=1 LED3=1 LED2=0 LED1=1
141110LED4=1 LED3=1 LED2=1 LED1=0
151111LED4=1 LED3=1 LED2=1 LED1=1

Note

When initializing a BusOut object you initialize pins in their bit order from right to left, be careful as the bit order is the reverse of the object initializing order.

// init object
BusOut thingy(pin0,pin1,...,pin15)

// use object
thingy = (val15<<15 | ... | val1 <<1 | val0 <<0) ; // where valx corresponds to the value to be put onto pinx

API

API summary

Import librarymbed

No documentation found.
Committer:
mbed_official
Date:
Mon Feb 11 17:29:01 2013 +0000
Revision:
0:717993c337df
Child:
2:f979089a5ca0
Hello World for BusOut

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:717993c337df 1 #include "mbed.h"
mbed_official 0:717993c337df 2
mbed_official 0:717993c337df 3 BusOut myleds(LED1, LED2, LED3, LED4);
mbed_official 0:717993c337df 4
mbed_official 0:717993c337df 5 int main() {
mbed_official 0:717993c337df 6 while(1) {
mbed_official 0:717993c337df 7 for(int i=0; i<16; i++) {
mbed_official 0:717993c337df 8 myleds = i;
mbed_official 0:717993c337df 9 wait(0.25);
mbed_official 0:717993c337df 10 }
mbed_official 0:717993c337df 11 }
mbed_official 0:717993c337df 12 }