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.
main.cpp@0:7811129277e5, 2020-02-08 (annotated)
- Committer:
- rxavi
- Date:
- Sat Feb 08 03:00:50 2020 +0000
- Revision:
- 0:7811129277e5
Lectura analogica con timer
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| rxavi | 0:7811129277e5 | 1 | #include "mbed.h" |
| rxavi | 0:7811129277e5 | 2 | Serial pc(PA_2,PA_3,115200); |
| rxavi | 0:7811129277e5 | 3 | Ticker flipper1; |
| rxavi | 0:7811129277e5 | 4 | Ticker flipper2; |
| rxavi | 0:7811129277e5 | 5 | |
| rxavi | 0:7811129277e5 | 6 | AnalogIn ain1(PC_1); |
| rxavi | 0:7811129277e5 | 7 | DigitalOut led1(PD_12); |
| rxavi | 0:7811129277e5 | 8 | DigitalOut led2(PD_14); |
| rxavi | 0:7811129277e5 | 9 | float sensor1=0.0; |
| rxavi | 0:7811129277e5 | 10 | float sensor2=0.0; |
| rxavi | 0:7811129277e5 | 11 | |
| rxavi | 0:7811129277e5 | 12 | void flip1() // flip 1 function |
| rxavi | 0:7811129277e5 | 13 | { |
| rxavi | 0:7811129277e5 | 14 | led1 = !led1; |
| rxavi | 0:7811129277e5 | 15 | sensor1 = ain1; |
| rxavi | 0:7811129277e5 | 16 | pc.printf("Valor1: %0.1f%%\n", sensor1*100); |
| rxavi | 0:7811129277e5 | 17 | } |
| rxavi | 0:7811129277e5 | 18 | |
| rxavi | 0:7811129277e5 | 19 | void flip2() // flip 2 function |
| rxavi | 0:7811129277e5 | 20 | { |
| rxavi | 0:7811129277e5 | 21 | led2 = !led2; |
| rxavi | 0:7811129277e5 | 22 | pc.printf("Valor2: %0.1f%%\n", sensor2); |
| rxavi | 0:7811129277e5 | 23 | } |
| rxavi | 0:7811129277e5 | 24 | |
| rxavi | 0:7811129277e5 | 25 | int main() |
| rxavi | 0:7811129277e5 | 26 | { |
| rxavi | 0:7811129277e5 | 27 | led1 = 0; |
| rxavi | 0:7811129277e5 | 28 | led2 = 0; |
| rxavi | 0:7811129277e5 | 29 | |
| rxavi | 0:7811129277e5 | 30 | flipper1.attach(&flip1, 0.2); // the address of the |
| rxavi | 0:7811129277e5 | 31 | // function to be attached |
| rxavi | 0:7811129277e5 | 32 | // and the interval (sec) |
| rxavi | 0:7811129277e5 | 33 | flipper2.attach(&flip2, 1.0); |
| rxavi | 0:7811129277e5 | 34 | // spin in a main loop |
| rxavi | 0:7811129277e5 | 35 | // flipper will interrupt it to call flip |
| rxavi | 0:7811129277e5 | 36 | |
| rxavi | 0:7811129277e5 | 37 | while(1) { |
| rxavi | 0:7811129277e5 | 38 | wait(0.2); |
| rxavi | 0:7811129277e5 | 39 | } |
| rxavi | 0:7811129277e5 | 40 | } |