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.
Fork of Task414 by
main.cpp@2:252ba8fbe314, 2019-09-18 (annotated)
- Committer:
- noutram
- Date:
- Wed Sep 18 13:11:06 2019 +0000
- Revision:
- 2:252ba8fbe314
- Parent:
- 0:a4f5053c990a
2019
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| noutram | 0:a4f5053c990a | 1 | #include "mbed.h" |
| noutram | 0:a4f5053c990a | 2 | #define kRED 4 |
| noutram | 0:a4f5053c990a | 3 | #define kYELLOW 2 |
| noutram | 0:a4f5053c990a | 4 | #define kGREEN 1 |
| noutram | 0:a4f5053c990a | 5 | |
| noutram | 0:a4f5053c990a | 6 | |
| noutram | 0:a4f5053c990a | 7 | //Global objects |
| noutram | 0:a4f5053c990a | 8 | BusOut binaryOutput(D5, D6, D7); |
| noutram | 0:a4f5053c990a | 9 | |
| noutram | 0:a4f5053c990a | 10 | DigitalIn SW1(D3); |
| noutram | 0:a4f5053c990a | 11 | DigitalIn SW2(D4); |
| noutram | 0:a4f5053c990a | 12 | |
| noutram | 0:a4f5053c990a | 13 | AnalogIn AIN(A0); |
| noutram | 0:a4f5053c990a | 14 | float fVin = 0.0; |
| noutram | 0:a4f5053c990a | 15 | |
| noutram | 0:a4f5053c990a | 16 | //Main function |
| noutram | 0:a4f5053c990a | 17 | int main() { |
| noutram | 0:a4f5053c990a | 18 | |
| noutram | 0:a4f5053c990a | 19 | |
| noutram | 0:a4f5053c990a | 20 | while(1) { |
| noutram | 0:a4f5053c990a | 21 | |
| noutram | 0:a4f5053c990a | 22 | //Read ADC |
| noutram | 0:a4f5053c990a | 23 | fVin = AIN; |
| noutram | 0:a4f5053c990a | 24 | |
| noutram | 0:a4f5053c990a | 25 | //Write to terminal |
| noutram | 0:a4f5053c990a | 26 | //3 decimal places, fieldwidth=5 |
| noutram | 0:a4f5053c990a | 27 | printf("Analog input = %6.4f\n", fVin); |
| noutram | 0:a4f5053c990a | 28 | |
| noutram | 0:a4f5053c990a | 29 | if (fVin < 0.4f) { |
| noutram | 0:a4f5053c990a | 30 | binaryOutput = kGREEN; |
| noutram | 0:a4f5053c990a | 31 | } else if (fVin < 0.6f) { |
| noutram | 0:a4f5053c990a | 32 | binaryOutput = kYELLOW; |
| noutram | 0:a4f5053c990a | 33 | } else { |
| noutram | 0:a4f5053c990a | 34 | binaryOutput = kRED; |
| noutram | 0:a4f5053c990a | 35 | } |
| noutram | 0:a4f5053c990a | 36 | |
| noutram | 0:a4f5053c990a | 37 | //Wait |
| noutram | 0:a4f5053c990a | 38 | wait(0.1); |
| noutram | 0:a4f5053c990a | 39 | |
| noutram | 0:a4f5053c990a | 40 | } //end while(1) |
| noutram | 0:a4f5053c990a | 41 | } //end main |
