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
main.cpp@0:8b55e947c1eb, 2019-04-10 (annotated)
- Committer:
- pbarrows
- Date:
- Wed Apr 10 16:00:27 2019 +0000
- Revision:
- 0:8b55e947c1eb
hi
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pbarrows | 0:8b55e947c1eb | 1 | #include "mbed.h" |
| pbarrows | 0:8b55e947c1eb | 2 | |
| pbarrows | 0:8b55e947c1eb | 3 | AnalogIn sensor(A1); |
| pbarrows | 0:8b55e947c1eb | 4 | |
| pbarrows | 0:8b55e947c1eb | 5 | int main() { |
| pbarrows | 0:8b55e947c1eb | 6 | float val; |
| pbarrows | 0:8b55e947c1eb | 7 | val=sensor.read(); //read the ADC value from pin PA1 |
| pbarrows | 0:8b55e947c1eb | 8 | //VOLTAGE / STEP = REFERENCE VOLTAGE / 4096 = (3.6V/4096= 0.879mV) per unit. |
| pbarrows | 0:8b55e947c1eb | 9 | float voltage=(val/4096)*3.6; //converts ADC value to voltage |
| pbarrows | 0:8b55e947c1eb | 10 | while(1) { |
| pbarrows | 0:8b55e947c1eb | 11 | printf("%.4f\n", voltage); // 0.0 to 1.0 |
| pbarrows | 0:8b55e947c1eb | 12 | wait_ms(100);} |
| pbarrows | 0:8b55e947c1eb | 13 | } |