Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
KPIT_MBED_worksheet/Topic3/Worksheet1_API.md
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
68 lines (55 sloc)
1.38 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~~~ | |
title: "Session 3: Worksheet 2" | |
author: "Dan Goldsmith" | |
~~~ | |
# Brief | |
For this task we are going to make use of the MBED API, to improve the | |
code we are writing. | |
Imagine we have been asked to write code to drive a light bar. | |
there are 4 LEDS that flash in a sequentail pattern. | |
| | Led 1 | Led 2 | Led 3 | Led 4 | | |
|---------|-------|-------|-------|-------| | |
| Stage 1 | X | | | | | |
| Stage 2 | | X | | | | |
| Stage 3 | | | X | | | |
| Stage 4 | | | | X | | |
\clearpage | |
## Initial Code | |
We could write code that looks like this | |
~~~ c | |
#include "mbed.h" | |
DigitalOut led(LED1); | |
DigitalOut led2(LED2); | |
DigitalOut led3(LED3); | |
DigitalOut led4(LED4); | |
int main() { | |
while (1) { | |
//Blink in an offset pattern | |
led = 1; | |
led2 = 0; | |
led3 = 0; | |
led4 = 0; | |
wait(0.5); | |
led = 0; | |
led2 = 1; | |
led3 = 0; | |
led4 = 0; | |
wait(0.5); | |
led = 0; | |
led2 = 0; | |
led3 = 1; | |
led4 = 0; | |
wait(0.5); | |
led = 0; | |
led2 = 0; | |
led3 = 0; | |
led4 = 1; | |
wait(0.5); | |
} | |
} | |
~~~ | |
## Task | |
However, its not the cleanest design. If we look at the MBED API | |
<https://os.mbed.com/docs/mbed-os/v5.11/apis/index.html> , it appears | |
the BUS interface is appropriate to use here. | |
Read the Bus API, and reimplement the code making use of this functionality. |