Thiago . / Mbed 2 deprecated ANALOGIN

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Sending Serial Values Read from AnalogIN
00002 // by Thiago Rech
00003 //
00004 //   When receiving the number '2', starts reading and sending the analog voltage in a 100Hz frequency*
00005 //
00006 // This is the first mbed project that I publish =D I would be thankfull if anyne give tips and point mistakes if any.
00007 
00008 
00009 #include "mbed.h"
00010 
00011 AnalogIn ain(PTB3);
00012 DigitalOut led2(LED2);  // Led red
00013 Ticker t1;              // Timer to send data
00014 Serial pc(USBTX, USBRX);
00015 
00016 void HandlerT1(void);
00017 void rx_Handler(void);
00018 
00019 volatile bool STATUS = true;
00020 char test = 0;
00021 
00022 int main()
00023 {
00024 
00025     //Setup
00026     pc.baud(9600);
00027     pc.printf("Press 2 to Start");
00028     pc.attach(&rx_Handler, pc.RxIrq);
00029     led2=0;
00030 
00031     while(1) {
00032 
00033         wait(0.5);                                  // Debug
00034         led2 = 0;
00035         pc.putc(test);                             // Debug
00036 
00037         if (teste == '2') {
00038             t1.attach(&HandlerT1, 0.01);
00039         }
00040 
00041         while(test == '2') {
00042 
00043             if (STATUS == true) {
00044 
00045                 STATUS = false;
00046                 led2 = 1;
00047                 pc.putc(analogValue);
00048                 pc.printf("0x%04X",ain.read_u16());
00049             }
00050 
00051 
00052         } //end of while(test=='2'){}
00053 
00054         t1.detach();    // Detaches timer interruption when not needed
00055     }//end of while(1)
00056 }//end of main
00057 
00058 void HandlerT1(void)
00059 {
00060     STATUS = true;
00061 }
00062 
00063 void rx_Handler(void)
00064 {
00065     test = pc.getc();
00066     pc.putc(test);
00067 }