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 Task411 by
main.cpp@3:00b294a944de, 2019-09-18 (annotated)
- Committer:
- noutram
- Date:
- Wed Sep 18 13:00:37 2019 +0000
- Revision:
- 3:00b294a944de
- Parent:
- 0:b2188dcbd1b1
2019
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| noutram | 0:b2188dcbd1b1 | 1 | #include "mbed.h" |
| noutram | 3:00b294a944de | 2 | //updated 2019 |
| noutram | 0:b2188dcbd1b1 | 3 | |
| noutram | 0:b2188dcbd1b1 | 4 | //Global objects |
| noutram | 0:b2188dcbd1b1 | 5 | BusOut binaryOutput(D5, D6, D7); //Outputs as an integer |
| noutram | 0:b2188dcbd1b1 | 6 | |
| noutram | 0:b2188dcbd1b1 | 7 | DigitalIn SW1(D3); |
| noutram | 0:b2188dcbd1b1 | 8 | DigitalIn SW2(D4); |
| noutram | 0:b2188dcbd1b1 | 9 | |
| noutram | 0:b2188dcbd1b1 | 10 | AnalogIn AIN(A0); |
| noutram | 0:b2188dcbd1b1 | 11 | float fVin = 0.0; |
| noutram | 0:b2188dcbd1b1 | 12 | |
| noutram | 0:b2188dcbd1b1 | 13 | //Main function |
| noutram | 0:b2188dcbd1b1 | 14 | int main() { |
| noutram | 0:b2188dcbd1b1 | 15 | |
| noutram | 0:b2188dcbd1b1 | 16 | |
| noutram | 0:b2188dcbd1b1 | 17 | while(1) { |
| noutram | 0:b2188dcbd1b1 | 18 | |
| noutram | 0:b2188dcbd1b1 | 19 | //Read ADC |
| noutram | 0:b2188dcbd1b1 | 20 | fVin = AIN; |
| noutram | 0:b2188dcbd1b1 | 21 | |
| noutram | 0:b2188dcbd1b1 | 22 | //Write to terminal |
| noutram | 0:b2188dcbd1b1 | 23 | printf("Analog input = %6.4f\n", fVin); //3 decimal places, fieldwidth=5 |
| noutram | 0:b2188dcbd1b1 | 24 | |
| noutram | 0:b2188dcbd1b1 | 25 | //Wait |
| noutram | 0:b2188dcbd1b1 | 26 | wait(0.5); |
| noutram | 0:b2188dcbd1b1 | 27 | |
| noutram | 0:b2188dcbd1b1 | 28 | } //end while(1) |
| noutram | 0:b2188dcbd1b1 | 29 | } //end main |
