Multímetro

Dependencies:   mbed LCDLib

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 
00005 
00006 DigitalOut led1(PC_13);
00007 TextLCD lcd(PA_4,PA_5,PA_6,PB_12,PB_13,PB_14,PB_15);
00008 AnalogIn adc(PA_0);
00009 AnalogIn tensaofixa(PA_1);
00010 Serial pc(PA_9, PA_10);// ver qual porta e rx e tx
00011 
00012 /*InterruptIn botao(PA_7);
00013 volatile bool botao_pressed = false; // Used in the main loop
00014 volatile bool botao_enabled = true; // Used for debouncing
00015 Timeout botao_timeout; // Used for debouncing
00016 
00017 // Enables button when bouncing is over
00018 void botao_enabled_cb(void)
00019 {
00020     botao_enabled = true;
00021 }
00022 
00023 // ISR handling button pressed event
00024 void botao_onpressed_cb(void)
00025 {
00026     if (botao_enabled) { // Disabled while the button is bouncing
00027         botao_enabled = false;
00028         botao_pressed = true; // To be read by the main loop
00029         botao_timeout.attach(callback(botao_enabled_cb), 0.3); // Debounce time 300 ms
00030     }
00031 }
00032 */
00033 
00034 int main()
00035 {
00036     float alim, tensao, corrente, resistencia;
00037     char cont;
00038     cont = '1';
00039     //button1.mode(PullUp); // Activate pull-up
00040     //botao.fall(callback(botao_onpressed_cb)); // Attach ISR to handle button press event
00041 
00042     while(1) {
00043         
00044         alim = 3.3*tensaofixa.read();
00045         tensao = 3.3*adc.read();
00046         resistencia = (tensao*1000)/(alim-tensao);
00047         corrente = (tensao/resistencia) * 1000;
00048         cont= pc.getc ();
00049         
00050         
00051        /* if (botao_pressed == true) { // Set when button is pressed
00052             botao_pressed = false;
00053             cont = cont++;        
00054             led1 = !led1;
00055         }
00056         if(cont == 4){
00057             cont = 1;    
00058         }
00059         */
00060         
00061         if(cont == '1'){
00062            //lcd.gotoxy(1,1);
00063             //lcd.printf("Tensao: %.2fV       ",tensao);
00064             pc.printf("Tensao: %.2fV       ",tensao);
00065             wait(0.2);
00066             
00067         }
00068         if(cont == '2'){
00069             //lcd.gotoxy(1,1);
00070             pc.printf("Corrente: %.2fmA       ",corrente);
00071             wait(0.2);
00072         }
00073         if(cont == '3'){
00074             //lcd.gotoxy(1,1);
00075             pc.printf("Res.:% .0fohm     ",resistencia);
00076             wait(0.2);
00077         }   
00078          
00079     }
00080 }