Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@4:90f9fff2e44e, 2021-10-21 (annotated)
- Committer:
- mgimple
- Date:
- Thu Oct 21 14:19:43 2021 +0000
- Revision:
- 4:90f9fff2e44e
- Parent:
- 3:f6547e1c1dfc
- Child:
- 5:f7e87403aca4
LED 2; LED 3; LED 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
slicht_instructor | 1:76d11e984b8d | 1 | //Base code for modification for Assignment 3.2 |
slicht_instructor | 1:76d11e984b8d | 2 | //Blinks LED2 every 200ms using a single Ticker object. |
slicht_instructor | 0:5597320f2dba | 3 | //Created: S. Licht, 10/04/2020 |
slicht_instructor | 1:76d11e984b8d | 4 | #include "mbed.h" |
mgimple | 4:90f9fff2e44e | 5 | Ticker tickerLED1; |
mgimple | 3:f6547e1c1dfc | 6 | Ticker tickerLED2; //create ticker object |
mgimple | 4:90f9fff2e44e | 7 | Ticker tickerLED3; |
mgimple | 4:90f9fff2e44e | 8 | DigitalOut LEDOut1(LED1); |
slicht_instructor | 1:76d11e984b8d | 9 | DigitalOut LEDOut2(LED2); |
mgimple | 3:f6547e1c1dfc | 10 | DigitalOut LEDOut3(LED3); |
mgimple | 4:90f9fff2e44e | 11 | InterruptIn butn(p17); //Interupts with pushbutton input p17 |
mgimple | 4:90f9fff2e44e | 12 | Timer debounce; //define debounce timer |
slicht_instructor | 0:5597320f2dba | 13 | |
slicht_instructor | 1:76d11e984b8d | 14 | void changeLED2() //the function that will be called by the ticker object. |
slicht_instructor | 1:76d11e984b8d | 15 | { |
slicht_instructor | 1:76d11e984b8d | 16 | LEDOut2 = !LEDOut2; |
slicht_instructor | 1:76d11e984b8d | 17 | } |
slicht_instructor | 0:5597320f2dba | 18 | |
mgimple | 3:f6547e1c1dfc | 19 | void changeLED3() //the function that will be called by the ticker object. |
mgimple | 3:f6547e1c1dfc | 20 | { |
mgimple | 3:f6547e1c1dfc | 21 | LEDOut3 = !LEDOut3; |
mgimple | 3:f6547e1c1dfc | 22 | } |
mgimple | 3:f6547e1c1dfc | 23 | |
mgimple | 4:90f9fff2e44e | 24 | void toggle() |
mgimple | 4:90f9fff2e44e | 25 | { |
mgimple | 4:90f9fff2e44e | 26 | if (debounce.read_ms()>200) { //only allow toggle if debounce timer |
mgimple | 4:90f9fff2e44e | 27 | LEDOut1=!LEDOut1; //has passed 200ms |
mgimple | 4:90f9fff2e44e | 28 | debounce.reset(); //restart timer when toggle is performed |
mgimple | 4:90f9fff2e44e | 29 | } |
mgimple | 4:90f9fff2e44e | 30 | } |
mgimple | 3:f6547e1c1dfc | 31 | |
slicht_instructor | 0:5597320f2dba | 32 | int main() |
slicht_instructor | 0:5597320f2dba | 33 | { |
mgimple | 4:90f9fff2e44e | 34 | debounce.start(); //start |
mgimple | 4:90f9fff2e44e | 35 | butn.rise(&toggle); |
mgimple | 4:90f9fff2e44e | 36 | tickerLED2.attach(&changeLED2,0.2); //the address of the function to call and the interval in seconds between calls to that function |
mgimple | 3:f6547e1c1dfc | 37 | tickerLED3.attach(&changeLED3,0.3); |
slicht_instructor | 0:5597320f2dba | 38 | } |
mgimple | 4:90f9fff2e44e | 39 | |
mgimple | 4:90f9fff2e44e | 40 | |
mgimple | 4:90f9fff2e44e | 41 |