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.  

BusIn

/media/uploads/mbedofficial/digitalin_interfaces.png

The BusIn interface is used to create a number of DigitalIn pins that can be read as one value.

Any of the numbered mbed pins can be used as a DigitalIn in the BusIn.

Hello World!

Control all the LEDs as a single value

#include "mbed.h"

BusIn nibble(p5, p6, p18, p11);

int main() {
    while(1) {
        switch(nibble) {
            case 0x3: printf("Hello!\n"); break; // p5 and p6 are 1
            case 0x8: printf("World!\n"); break; // p11 is 1
        }
    }
}

API

API summary

BusInA digital input bus, used for reading the state of a collection of pins
Configuration Methods
BusInCreate an BusIn, connected to the specified pins
Access Methods
readRead the value of the input bus
Access Method Shorthand
operator int()A shorthand for read
class BusIn : public Base
A digital input bus, used for reading the state of a collection of pins
BusIn(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 BusIn, connected to the specified pins
int read()
Read the value of the input bus
operator int()
A shorthand for read

Related




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

3 comments on BusIn:

09 Jun 2011

I would like to suggest that the constructor be documented to state that the parameters are specified in LSB-to-MSB order, rather than implicitly as demonstrated in the example.

Although this ordering makes sense from an API definition standpoint, it's likely the opposite sense that a noob would assume (MSB on the left, LSB on the right).

06 Dec 2011

I am a newbie. Here what is meant by case 0x3, case 0x8

08 Dec 2011

Hello Atanu, You can imagine BUS as series of bits. In example is created BUS named nibble (it means half byte - four bits) but You can name it as You wish. If You read state of the bus, You will get number (easy to use HEX numbers) which represents state of inputs in the BUS. This is input BUS so each pin in bus can have value 0 or 1. So if You read BUS, You will get 0000 - bin (0x0 hex) if no input or 1111 - bin (0xF hex) if all inputs in BUS are high. You will get 0x3 hex (0011 in bin) reading if pin 5 and 6 is High. And reading 0x8 hex (1000 bin) if pin 11 is high.

In the code is used "switch" command and as parameter is used actual status of BUS. So if p5 and p6 are high program reads bus as 0011 bin (0x3 Hex) and does what is specified in "case" for this value. In this example it prints Hello on terminal. If only p11 is High program reads it as 0x8 hex and again does what is specified in "case" for this value - prints World on terminal. For other combinations of pins are not specified cases so if pin 18 is high, program does nothing. But You can try to add Your case to see how it works.

Example state of bus:

pin - pin 11 , pin 18 , pin 6 , pin 5

state - 0 0 1 1

Pins 11 & 18 are low - 0 and pins 6 & 5 are high - 1. The reading of the bus is 0011 bin or 0x03 in hex.

You can also look on internet for "bit masking" You can use bitmasking to determine which of busIn pins are high - (nibble && 0x8).

Please login to post comments.