Aplicações de Microcontroladores
/
Aula_2
Multímetro
Diff: main.cpp
- Revision:
- 1:808bed0f2433
- Parent:
- 0:be36515913f8
- Child:
- 2:fb35f75110ee
--- a/main.cpp Thu Jun 13 14:34:19 2019 +0000 +++ b/main.cpp Thu Jun 27 12:44:36 2019 +0000 @@ -5,6 +5,7 @@ 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); InterruptIn botao(PA_7); volatile bool botao_pressed = false; // Used in the main loop @@ -30,7 +31,7 @@ int main() { - float tensao; + float alim, tensao, corrente, resistencia; int cont; cont = 1; //button1.mode(PullUp); // Activate pull-up @@ -38,31 +39,35 @@ while(1) { + alim = 3.3*tensaofixa.read(); tensao = 3.3*adc.read(); + resistencia = (tensao*1000)/(alim-tensao); + corrente = (tensao/resistencia) * 1000; if (botao_pressed == true) { // Set when button is pressed botao_pressed = false; cont = cont++; led1 = !led1; } - if(cont == 5){ + if(cont == 4){ cont = 1; } if(cont == 1){ lcd.gotoxy(1,1); lcd.printf("Tensao: %.2fV ",tensao); + wait(0.2); + } if(cont == 2){ lcd.gotoxy(1,1); - lcd.printf("Corrente: %.2fA ",tensao); + lcd.printf("Corrente: %.2fmA ",corrente); + wait(0.2); } if(cont == 3){ lcd.gotoxy(1,1); - lcd.printf("Resist.:% .2fohm",tensao); + lcd.printf("Res.:% .0fohm ",resistencia); + wait(0.2); } - if(cont == 4){ - lcd.gotoxy(1,1); - lcd.printf("Freq.:% .2fHz ",tensao); - } + } }