![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Manejo de interrupciones para lectura de senal analoga.
main.cpp@0:fe729db7d621, 2020-02-08 (annotated)
- Committer:
- javierdavid2006
- Date:
- Sat Feb 08 02:59:13 2020 +0000
- Revision:
- 0:fe729db7d621
Manejo de Interrupciones
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
javierdavid2006 | 0:fe729db7d621 | 1 | #include "mbed.h" |
javierdavid2006 | 0:fe729db7d621 | 2 | AnalogIn sensor(PB_0); |
javierdavid2006 | 0:fe729db7d621 | 3 | Ticker flipper1; |
javierdavid2006 | 0:fe729db7d621 | 4 | Ticker flipper2; |
javierdavid2006 | 0:fe729db7d621 | 5 | DigitalOut led1(PD_13); |
javierdavid2006 | 0:fe729db7d621 | 6 | DigitalOut led2(PD_8); |
javierdavid2006 | 0:fe729db7d621 | 7 | float valor_analogo; |
javierdavid2006 | 0:fe729db7d621 | 8 | Serial device(PA_2,PA_3); |
javierdavid2006 | 0:fe729db7d621 | 9 | |
javierdavid2006 | 0:fe729db7d621 | 10 | void flip1() // flip 1 function |
javierdavid2006 | 0:fe729db7d621 | 11 | { |
javierdavid2006 | 0:fe729db7d621 | 12 | valor_analogo=sensor.read(); |
javierdavid2006 | 0:fe729db7d621 | 13 | device.printf("El valor analogo es en el timmer_1: %f \r\n", valor_analogo); |
javierdavid2006 | 0:fe729db7d621 | 14 | |
javierdavid2006 | 0:fe729db7d621 | 15 | } |
javierdavid2006 | 0:fe729db7d621 | 16 | |
javierdavid2006 | 0:fe729db7d621 | 17 | void flip2() // flip 2 function |
javierdavid2006 | 0:fe729db7d621 | 18 | { |
javierdavid2006 | 0:fe729db7d621 | 19 | valor_analogo=sensor.read(); |
javierdavid2006 | 0:fe729db7d621 | 20 | device.printf("El valor analogo es en timmer_2: %f \r\n", valor_analogo); |
javierdavid2006 | 0:fe729db7d621 | 21 | |
javierdavid2006 | 0:fe729db7d621 | 22 | } |
javierdavid2006 | 0:fe729db7d621 | 23 | int main() |
javierdavid2006 | 0:fe729db7d621 | 24 | { |
javierdavid2006 | 0:fe729db7d621 | 25 | device.baud(9600);//Velocidad de Comunicacion |
javierdavid2006 | 0:fe729db7d621 | 26 | led1 = 0; |
javierdavid2006 | 0:fe729db7d621 | 27 | led2 = 0; |
javierdavid2006 | 0:fe729db7d621 | 28 | |
javierdavid2006 | 0:fe729db7d621 | 29 | flipper1.attach(&flip1, 0.2); // the address of the |
javierdavid2006 | 0:fe729db7d621 | 30 | // function to be attached |
javierdavid2006 | 0:fe729db7d621 | 31 | // and the interval (sec) |
javierdavid2006 | 0:fe729db7d621 | 32 | flipper2.attach(&flip2, 1.0); |
javierdavid2006 | 0:fe729db7d621 | 33 | // spin in a main loop |
javierdavid2006 | 0:fe729db7d621 | 34 | // flipper will interrupt it to call flip |
javierdavid2006 | 0:fe729db7d621 | 35 | |
javierdavid2006 | 0:fe729db7d621 | 36 | while(1) { |
javierdavid2006 | 0:fe729db7d621 | 37 | wait(0.2); |
javierdavid2006 | 0:fe729db7d621 | 38 | } |
javierdavid2006 | 0:fe729db7d621 | 39 | } |