BusOut Hello World
Fork of BusOut_HelloWorld by
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.
Integer | binary | LED On(1) / Off(0) |
---|---|---|
0 | 0000 | LED4=0 LED3=0 LED2=0 LED1=0 |
1 | 0001 | LED4=0 LED3=0 LED2=0 LED1=1 |
2 | 0010 | LED4=0 LED3=0 LED2=1 LED1=0 |
3 | 0011 | LED4=0 LED3=0 LED2=1 LED1=1 |
4 | 0100 | LED4=0 LED3=1 LED2=0 LED1=0 |
5 | 0101 | LED4=0 LED3=1 LED2=0 LED1=1 |
6 | 0110 | LED4=0 LED3=1 LED2=1 LED1=0 |
7 | 0111 | LED4=0 LED3=1 LED2=1 LED1=1 |
8 | 1000 | LED4=1 LED3=0 LED2=0 LED1=0 |
9 | 1001 | LED4=1 LED3=0 LED2=0 LED1=1 |
10 | 1010 | LED4=1 LED3=0 LED2=1 LED1=0 |
11 | 1011 | LED4=1 LED3=0 LED2=1 LED1=1 |
12 | 1100 | LED4=1 LED3=1 LED2=0 LED1=0 |
13 | 1101 | LED4=1 LED3=1 LED2=0 LED1=1 |
14 | 1110 | LED4=1 LED3=1 LED2=1 LED1=0 |
15 | 1111 | LED4=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
main.cpp@4:b07a5ecb7618, 2017-06-24 (annotated)
- Committer:
- sarahmarshy
- Date:
- Sat Jun 24 18:44:55 2017 -0500
- Revision:
- 4:b07a5ecb7618
- Parent:
- 2:f979089a5ca0
"Update mbed-os"
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 2:f979089a5ca0 | 1 | /* mbed Example Program |
mbedAustin | 2:f979089a5ca0 | 2 | * Copyright (c) 2006-2014 ARM Limited |
mbedAustin | 2:f979089a5ca0 | 3 | * |
mbedAustin | 2:f979089a5ca0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbedAustin | 2:f979089a5ca0 | 5 | * you may not use this file except in compliance with the License. |
mbedAustin | 2:f979089a5ca0 | 6 | * You may obtain a copy of the License at |
mbedAustin | 2:f979089a5ca0 | 7 | * |
mbedAustin | 2:f979089a5ca0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 2:f979089a5ca0 | 9 | * |
mbedAustin | 2:f979089a5ca0 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 2:f979089a5ca0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbedAustin | 2:f979089a5ca0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 2:f979089a5ca0 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 2:f979089a5ca0 | 14 | * limitations under the License. |
mbedAustin | 2:f979089a5ca0 | 15 | */ |
mbed_official | 0:717993c337df | 16 | #include "mbed.h" |
mbed_official | 0:717993c337df | 17 | |
mbed_official | 0:717993c337df | 18 | BusOut myleds(LED1, LED2, LED3, LED4); |
mbed_official | 0:717993c337df | 19 | |
mbed_official | 0:717993c337df | 20 | int main() { |
mbed_official | 0:717993c337df | 21 | while(1) { |
mbed_official | 0:717993c337df | 22 | for(int i=0; i<16; i++) { |
mbed_official | 0:717993c337df | 23 | myleds = i; |
mbed_official | 0:717993c337df | 24 | wait(0.25); |
mbed_official | 0:717993c337df | 25 | } |
mbed_official | 0:717993c337df | 26 | } |
mbed_official | 0:717993c337df | 27 | } |