Multímetro

Dependencies:   mbed LCDLib

main.cpp

Committer:
meksc
Date:
2019-07-04
Revision:
2:fb35f75110ee
Parent:
1:808bed0f2433

File content as of revision 2:fb35f75110ee:

#include "mbed.h"
#include "TextLCD.h"



DigitalOut led1(PC_13);
TextLCD lcd(PA_4,PA_5,PA_6,PB_12,PB_13,PB_14,PB_15);
AnalogIn adc(PA_0);
AnalogIn tensaofixa(PA_1);
Serial pc(PA_9, PA_10);// ver qual porta e rx e tx

/*InterruptIn botao(PA_7);
volatile bool botao_pressed = false; // Used in the main loop
volatile bool botao_enabled = true; // Used for debouncing
Timeout botao_timeout; // Used for debouncing

// Enables button when bouncing is over
void botao_enabled_cb(void)
{
    botao_enabled = true;
}

// ISR handling button pressed event
void botao_onpressed_cb(void)
{
    if (botao_enabled) { // Disabled while the button is bouncing
        botao_enabled = false;
        botao_pressed = true; // To be read by the main loop
        botao_timeout.attach(callback(botao_enabled_cb), 0.3); // Debounce time 300 ms
    }
}
*/

int main()
{
    float alim, tensao, corrente, resistencia;
    char cont;
    cont = '1';
    //button1.mode(PullUp); // Activate pull-up
    //botao.fall(callback(botao_onpressed_cb)); // Attach ISR to handle button press event

    while(1) {
        
        alim = 3.3*tensaofixa.read();
        tensao = 3.3*adc.read();
        resistencia = (tensao*1000)/(alim-tensao);
        corrente = (tensao/resistencia) * 1000;
        cont= pc.getc ();
        
        
       /* if (botao_pressed == true) { // Set when button is pressed
            botao_pressed = false;
            cont = cont++;        
            led1 = !led1;
        }
        if(cont == 4){
            cont = 1;    
        }
        */
        
        if(cont == '1'){
           //lcd.gotoxy(1,1);
            //lcd.printf("Tensao: %.2fV       ",tensao);
            pc.printf("Tensao: %.2fV       ",tensao);
            wait(0.2);
            
        }
        if(cont == '2'){
            //lcd.gotoxy(1,1);
            pc.printf("Corrente: %.2fmA       ",corrente);
            wait(0.2);
        }
        if(cont == '3'){
            //lcd.gotoxy(1,1);
            pc.printf("Res.:% .0fohm     ",resistencia);
            wait(0.2);
        }   
         
    }
}