Starting from:

$29.99

Assignment 1 – Working with LEDs and switches

Assignment 1 – Working with LEDs and switches
Connect your mbed to the LEDs, switches, and resistors as shown in the schematic below:
Note that there are both active-high as well as active-low switches and LEDs. This will give you
practice with all of the cases.
Initially, the 4 blue LEDs built into the mbed itself should be off. Each time Switch 2 is pressed,
one of the blue LEDs that is off should be turned on. Each time Switch 1 is pressed, one of the
blue LEDs that is on should be turned off. In either case, if there are no blue LEDs in the
appropriate state (off for Switch 2 or on for Switch 1) then nothing should change.
The red LED should be on if and only if all of the blue LEDs are off. The green LED should be
on if and only if all of the blue LEDs are on.
You may assume that no more than one switch is pressed at a time. The program should be
usable on a human time scale (either look for a press/release cycle, or ensure that if a switch is
held down it does not repeat the associated action faster than once per 500 ms). Be sure to
compensate for spurious edges due to switch bounce. The program should be written to use the
DigitalIn and DigitalOut classes from mbed OS 2 (state with the “Blinky LED Hello World”
template).
Upload your final “main.cpp” file to the Assignment 1 dropbox on Canvas by the end of
February 16th. Do not upload the bin file that you have saved to the mbed. Instead, use the
export option which will allow you to download main.cpp from the mbed web site to your
computer so that you can then upload it the Canvas. See “How to export main.cpp from the mbed
web site” on Canvas for details.
VOUT
p21
p22
220 Ω
green
LED
220 Ω
red
LED
p20
p19
GND
switch 1 switch 2
mbed

More products