Carlos Quintana / Mbed 2 deprecated frdm_gpioADC_LCDpublic

Dependencies:   mbed TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 
00004 AnalogIn Canal1(A1); //PTB3
00005 AnalogIn Canal0(A0); //PTB2
00006 
00007 InterruptIn btn(PTA2);
00008 
00009 DigitalOut led(LED_RED,1);
00010 DigitalOut led2(LED_BLUE,1);
00011 
00012 TextLCD LCD(PTC2, PTC3, PTD0, PTD1, PTD2, PTD3); //rs, en, D4, D5, D6, D7
00013 
00014 bool sw = false;
00015 float AdcFlt;
00016 
00017 void ISR_Switch()
00018 {
00019     sw = !sw;  
00020     LCD.cls();
00021     wait(0.25);     
00022 }
00023 
00024 int main()
00025 {
00026     btn.mode(PullUp);
00027     btn.rise(&ISR_Switch);
00028     
00029     wait(0.25);
00030     LCD.cls();
00031     wait(0.25);
00032     
00033     while (true) 
00034     {
00035         if (sw == 0)
00036         {
00037             LCD.locate(0,0);
00038             LCD.printf("CH0 Valor: %5d",Canal0.read_u16());
00039             LCD.locate(0,1);
00040             LCD.printf("CH1 Valor: %5d",Canal1.read_u16());
00041             led = 0;
00042             wait(0.05);
00043             led = 1;
00044             wait(0.45);
00045         }
00046         else 
00047         {
00048             AdcFlt = Canal0.read_u16()*3.3/65536;
00049             LCD.locate(0,0);
00050             LCD.printf("CH0 Volts: %.3f",AdcFlt);
00051             AdcFlt = Canal1.read_u16()*3.3/65536;
00052             LCD.locate(0,1);
00053             LCD.printf("CH1 Volts: %.3f",AdcFlt);
00054             led2 = 0;
00055             wait(0.05);
00056             led2 = 1;
00057             wait(0.45);    
00058         }               
00059     }
00060 }