Richard Sanchez Pozo / Mbed 2 deprecated Lectura_AnalogIn_interrupcion

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 Serial pc(PA_2,PA_3,115200);
00003 Ticker flipper1;
00004 Ticker flipper2;
00005 
00006 AnalogIn ain1(PC_1);
00007 DigitalOut led1(PD_12);
00008 DigitalOut led2(PD_14);
00009 float sensor1=0.0;
00010 float sensor2=0.0;
00011 
00012 void flip1()   // flip 1 function
00013 {
00014     led1 = !led1;
00015     sensor1 = ain1;
00016     pc.printf("Valor1: %0.1f%%\n", sensor1*100);
00017 }
00018 
00019 void flip2()   // flip 2 function
00020 {
00021     led2 = !led2;
00022     pc.printf("Valor2: %0.1f%%\n", sensor2);
00023 }
00024 
00025 int main()
00026 {
00027     led1 = 0;
00028     led2 = 0;
00029 
00030     flipper1.attach(&flip1, 0.2); // the address of the
00031 // function to be attached
00032 // and the interval (sec)
00033     flipper2.attach(&flip2, 1.0);
00034 // spin in a main loop
00035 // flipper will interrupt it to call flip
00036 
00037     while(1) {
00038         wait(0.2);
00039     }
00040 }