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.
Dependencies: mbed TTU_CSC1300
main.cpp@2:651e6edca37a, 2021-04-13 (annotated)
- Committer:
- evamaffett
- Date:
- Tue Apr 13 03:34:42 2021 +0000
- Revision:
- 2:651e6edca37a
- Parent:
- 1:c9aa78523331
conditional statements
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| evamaffett | 0:911c8f66a59d | 1 | /* |
| evamaffett | 2:651e6edca37a | 2 | * Lab #: 3 |
| evamaffett | 2:651e6edca37a | 3 | * Lab Title: Conditional Statements |
| evamaffett | 2:651e6edca37a | 4 | * Author(s): Eva Maffett |
| evamaffett | 2:651e6edca37a | 5 | * Date: 4-12-2021 |
| evamaffett | 2:651e6edca37a | 6 | * Purpose: Use conditional branching to control speaker and LED outputs |
| evamaffett | 0:911c8f66a59d | 7 | */ |
| evamaffett | 0:911c8f66a59d | 8 | |
| evamaffett | 0:911c8f66a59d | 9 | #include "mbed.h" |
| evamaffett | 0:911c8f66a59d | 10 | #include "TTU_CSC1300.h" |
| evamaffett | 0:911c8f66a59d | 11 | |
| evamaffett | 0:911c8f66a59d | 12 | //FUNCTION PROTOTYPES GO HERE |
| evamaffett | 0:911c8f66a59d | 13 | |
| evamaffett | 0:911c8f66a59d | 14 | int main() |
| evamaffett | 0:911c8f66a59d | 15 | { |
| evamaffett | 0:911c8f66a59d | 16 | //this while(TRUE) loop keeps the program running |
| evamaffett | 0:911c8f66a59d | 17 | while(TRUE) |
| evamaffett | 0:911c8f66a59d | 18 | { |
| evamaffett | 0:911c8f66a59d | 19 | //WRITE SOLUTION HERE |
| evamaffett | 0:911c8f66a59d | 20 | float f_value = pot.read(); //f_value > 0.0f && f_value < 1.0f |
| evamaffett | 0:911c8f66a59d | 21 | f_value = (f_value * 25) + 20; |
| evamaffett | 1:c9aa78523331 | 22 | if (bool sw5_pressed = TRUE && f_value > 35){ |
| evamaffett | 1:c9aa78523331 | 23 | speaker = TRUE; //will turn the speaker on, sending a single square wave |
| evamaffett | 1:c9aa78523331 | 24 | wait_ms(250); //delays for 250 ms |
| evamaffett | 1:c9aa78523331 | 25 | speaker = FALSE; //will turn the speaker off |
| evamaffett | 1:c9aa78523331 | 26 | led0 = TRUE; |
| evamaffett | 1:c9aa78523331 | 27 | wait_ms(500); |
| evamaffett | 1:c9aa78523331 | 28 | led0 = FALSE; |
| evamaffett | 1:c9aa78523331 | 29 | wait_ms(500); |
| evamaffett | 1:c9aa78523331 | 30 | wait_ms(f_value); |
| evamaffett | 2:651e6edca37a | 31 | } else if (bool sw4_pressed = TRUE){ |
| evamaffett | 1:c9aa78523331 | 32 | speaker = TRUE; //will turn the speaker on, sending a single square wave |
| evamaffett | 1:c9aa78523331 | 33 | wait_ms(250); //delays for 250 ms |
| evamaffett | 1:c9aa78523331 | 34 | speaker = FALSE; //will turn the speaker off |
| evamaffett | 1:c9aa78523331 | 35 | led0 = TRUE; |
| evamaffett | 1:c9aa78523331 | 36 | wait_ms(500); |
| evamaffett | 1:c9aa78523331 | 37 | led0 = FALSE; |
| evamaffett | 1:c9aa78523331 | 38 | wait_ms(500); |
| evamaffett | 1:c9aa78523331 | 39 | wait_ms(f_value); |
| evamaffett | 2:651e6edca37a | 40 | } else { |
| evamaffett | 2:651e6edca37a | 41 | speaker = TRUE; |
| evamaffett | 2:651e6edca37a | 42 | wait_ms(f_value); |
| evamaffett | 1:c9aa78523331 | 43 | } |
| evamaffett | 0:911c8f66a59d | 44 | } |
| evamaffett | 0:911c8f66a59d | 45 | } |