Richson Ngu
/
SectionA-1_Richson_19Feb
UPDATED 19FEB
main.cpp@2:50d62982790c, 2019-01-23 (annotated)
- Committer:
- selvakumararm
- Date:
- Wed Jan 23 02:50:29 2019 +0000
- Revision:
- 2:50d62982790c
- Parent:
- 1:5f6d4748c3ff
- Child:
- 3:a1439fe436e9
Mock Exam Template code
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
selvakumararm | 0:bcf6fcde4f32 | 1 | #include "mbed.h" |
selvakumararm | 0:bcf6fcde4f32 | 2 | |
selvakumararm | 0:bcf6fcde4f32 | 3 | DigitalOut myled(LED1); |
selvakumararm | 0:bcf6fcde4f32 | 4 | InterruptIn button1(USER_BUTTON); |
selvakumararm | 0:bcf6fcde4f32 | 5 | |
selvakumararm | 0:bcf6fcde4f32 | 6 | bool active = false; |
selvakumararm | 0:bcf6fcde4f32 | 7 | |
selvakumararm | 0:bcf6fcde4f32 | 8 | void BUTTON_ISR(){ |
selvakumararm | 0:bcf6fcde4f32 | 9 | active = !active; |
selvakumararm | 0:bcf6fcde4f32 | 10 | } |
selvakumararm | 0:bcf6fcde4f32 | 11 | |
selvakumararm | 0:bcf6fcde4f32 | 12 | int main() { |
selvakumararm | 0:bcf6fcde4f32 | 13 | // Set up |
selvakumararm | 0:bcf6fcde4f32 | 14 | button1.mode(PullUp); |
selvakumararm | 0:bcf6fcde4f32 | 15 | button1.fall(&BUTTON_ISR); |
selvakumararm | 0:bcf6fcde4f32 | 16 | |
selvakumararm | 2:50d62982790c | 17 | if(active == true){ |
selvakumararm | 0:bcf6fcde4f32 | 18 | myled = 1; // LED is ON |
selvakumararm | 0:bcf6fcde4f32 | 19 | wait(0.2); // 200 ms |
selvakumararm | 2:50d62982790c | 20 | <<<<<<<<<YOUR CODE SHOULD BE HEREE>>>> |
selvakumararm | 0:bcf6fcde4f32 | 21 | } |
selvakumararm | 0:bcf6fcde4f32 | 22 | else{ |
selvakumararm | 0:bcf6fcde4f32 | 23 | myled = 0; |
selvakumararm | 0:bcf6fcde4f32 | 24 | } |
selvakumararm | 0:bcf6fcde4f32 | 25 | __wfi(); //Wait for interruptions |
selvakumararm | 0:bcf6fcde4f32 | 26 | } |
selvakumararm | 0:bcf6fcde4f32 | 27 | } |
selvakumararm | 0:bcf6fcde4f32 | 28 | |
selvakumararm | 0:bcf6fcde4f32 | 29 |