![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
aaaaa
Dependencies: mbed Grove_LCD_RGB_Backlight
lab4b.cpp@0:468c9208499f, 2020-08-27 (annotated)
- Committer:
- DavidRoss
- Date:
- Thu Aug 27 17:18:10 2020 +0000
- Revision:
- 0:468c9208499f
- Child:
- 1:d800035aa2d9
good version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DavidRoss | 0:468c9208499f | 1 | /* |
DavidRoss | 0:468c9208499f | 2 | Title: Using Pushbuttons to selectively blink a RED/Green Led |
DavidRoss | 0:468c9208499f | 3 | Author: Your Name,Student Id, Course Code, Lab Section |
DavidRoss | 0:468c9208499f | 4 | Date: Today's Date |
DavidRoss | 0:468c9208499f | 5 | Description: This program will turn ON/OFF the red led if the |
DavidRoss | 0:468c9208499f | 6 | left pushbutton is pressed or the green led if the |
DavidRoss | 0:468c9208499f | 7 | right pushbutton is pressed. |
DavidRoss | 0:468c9208499f | 8 | */ |
DavidRoss | 0:468c9208499f | 9 | |
DavidRoss | 0:468c9208499f | 10 | #include "mbed.h" // include the mbed library |
DavidRoss | 0:468c9208499f | 11 | |
DavidRoss | 0:468c9208499f | 12 | DigitalOut led_red(LED_RED); // led_red is set to RED LED pin |
DavidRoss | 0:468c9208499f | 13 | DigitalOut led_green(LED_GREEN); // led_green is set to GREEN LED pin |
DavidRoss | 0:468c9208499f | 14 | DigitalIn left_pb(SW3); // left_pb is set to left pb pin |
DavidRoss | 0:468c9208499f | 15 | DigitalIn right_pb(SW2); // right pb is set to right pb pin |
DavidRoss | 0:468c9208499f | 16 | |
DavidRoss | 0:468c9208499f | 17 | int main() |
DavidRoss | 0:468c9208499f | 18 | { |
DavidRoss | 0:468c9208499f | 19 | led_red=led_green=1; // turn red and green leds off |
DavidRoss | 0:468c9208499f | 20 | for(;;) |
DavidRoss | 0:468c9208499f | 21 | { |
DavidRoss | 0:468c9208499f | 22 | if(left_pb==0) // if left pb is pressed |
DavidRoss | 0:468c9208499f | 23 | { |
DavidRoss | 0:468c9208499f | 24 | led_red=1; // red led is off |
DavidRoss | 0:468c9208499f | 25 | wait_ms(500); |
DavidRoss | 0:468c9208499f | 26 | led_red=0; // red led is on |
DavidRoss | 0:468c9208499f | 27 | wait_ms(500); |
DavidRoss | 0:468c9208499f | 28 | } |
DavidRoss | 0:468c9208499f | 29 | else |
DavidRoss | 0:468c9208499f | 30 | if(right_pb==0) // else if rigth pb is pressed |
DavidRoss | 0:468c9208499f | 31 | { |
DavidRoss | 0:468c9208499f | 32 | led_green=1; // green led is off |
DavidRoss | 0:468c9208499f | 33 | wait_ms(500); |
DavidRoss | 0:468c9208499f | 34 | led_green=0; // green led is on |
DavidRoss | 0:468c9208499f | 35 | wait_ms(500); |
DavidRoss | 0:468c9208499f | 36 | } |
DavidRoss | 0:468c9208499f | 37 | else |
DavidRoss | 0:468c9208499f | 38 | { |
DavidRoss | 0:468c9208499f | 39 | led_red=led_green=1; // turn red and green leds off |
DavidRoss | 0:468c9208499f | 40 | } |
DavidRoss | 0:468c9208499f | 41 | } |
DavidRoss | 0:468c9208499f | 42 | } |