Multímetro

Dependencies:   mbed LCDLib

Committer:
MaikonJT
Date:
Thu Jun 27 12:44:36 2019 +0000
Revision:
1:808bed0f2433
Parent:
0:be36515913f8
Child:
2:fb35f75110ee
-

Who changed what in which revision?

UserRevisionLine numberNew contents of line
felipealboy 0:be36515913f8 1 #include "mbed.h"
felipealboy 0:be36515913f8 2 #include "TextLCD.h"
felipealboy 0:be36515913f8 3
felipealboy 0:be36515913f8 4
felipealboy 0:be36515913f8 5 DigitalOut led1(PC_13);
felipealboy 0:be36515913f8 6 TextLCD lcd(PA_4,PA_5,PA_6,PB_12,PB_13,PB_14,PB_15);
felipealboy 0:be36515913f8 7 AnalogIn adc(PA_0);
MaikonJT 1:808bed0f2433 8 AnalogIn tensaofixa(PA_1);
felipealboy 0:be36515913f8 9
felipealboy 0:be36515913f8 10 InterruptIn botao(PA_7);
felipealboy 0:be36515913f8 11 volatile bool botao_pressed = false; // Used in the main loop
felipealboy 0:be36515913f8 12 volatile bool botao_enabled = true; // Used for debouncing
felipealboy 0:be36515913f8 13 Timeout botao_timeout; // Used for debouncing
felipealboy 0:be36515913f8 14
felipealboy 0:be36515913f8 15 // Enables button when bouncing is over
felipealboy 0:be36515913f8 16 void botao_enabled_cb(void)
felipealboy 0:be36515913f8 17 {
felipealboy 0:be36515913f8 18 botao_enabled = true;
felipealboy 0:be36515913f8 19 }
felipealboy 0:be36515913f8 20
felipealboy 0:be36515913f8 21 // ISR handling button pressed event
felipealboy 0:be36515913f8 22 void botao_onpressed_cb(void)
felipealboy 0:be36515913f8 23 {
felipealboy 0:be36515913f8 24 if (botao_enabled) { // Disabled while the button is bouncing
felipealboy 0:be36515913f8 25 botao_enabled = false;
felipealboy 0:be36515913f8 26 botao_pressed = true; // To be read by the main loop
felipealboy 0:be36515913f8 27 botao_timeout.attach(callback(botao_enabled_cb), 0.3); // Debounce time 300 ms
felipealboy 0:be36515913f8 28 }
felipealboy 0:be36515913f8 29 }
felipealboy 0:be36515913f8 30
felipealboy 0:be36515913f8 31
felipealboy 0:be36515913f8 32 int main()
felipealboy 0:be36515913f8 33 {
MaikonJT 1:808bed0f2433 34 float alim, tensao, corrente, resistencia;
felipealboy 0:be36515913f8 35 int cont;
felipealboy 0:be36515913f8 36 cont = 1;
felipealboy 0:be36515913f8 37 //button1.mode(PullUp); // Activate pull-up
felipealboy 0:be36515913f8 38 botao.fall(callback(botao_onpressed_cb)); // Attach ISR to handle button press event
felipealboy 0:be36515913f8 39
felipealboy 0:be36515913f8 40 while(1) {
felipealboy 0:be36515913f8 41
MaikonJT 1:808bed0f2433 42 alim = 3.3*tensaofixa.read();
felipealboy 0:be36515913f8 43 tensao = 3.3*adc.read();
MaikonJT 1:808bed0f2433 44 resistencia = (tensao*1000)/(alim-tensao);
MaikonJT 1:808bed0f2433 45 corrente = (tensao/resistencia) * 1000;
felipealboy 0:be36515913f8 46
felipealboy 0:be36515913f8 47 if (botao_pressed == true) { // Set when button is pressed
felipealboy 0:be36515913f8 48 botao_pressed = false;
felipealboy 0:be36515913f8 49 cont = cont++;
felipealboy 0:be36515913f8 50 led1 = !led1;
felipealboy 0:be36515913f8 51 }
MaikonJT 1:808bed0f2433 52 if(cont == 4){
felipealboy 0:be36515913f8 53 cont = 1;
felipealboy 0:be36515913f8 54 }
felipealboy 0:be36515913f8 55 if(cont == 1){
felipealboy 0:be36515913f8 56 lcd.gotoxy(1,1);
felipealboy 0:be36515913f8 57 lcd.printf("Tensao: %.2fV ",tensao);
MaikonJT 1:808bed0f2433 58 wait(0.2);
MaikonJT 1:808bed0f2433 59
felipealboy 0:be36515913f8 60 }
felipealboy 0:be36515913f8 61 if(cont == 2){
felipealboy 0:be36515913f8 62 lcd.gotoxy(1,1);
MaikonJT 1:808bed0f2433 63 lcd.printf("Corrente: %.2fmA ",corrente);
MaikonJT 1:808bed0f2433 64 wait(0.2);
felipealboy 0:be36515913f8 65 }
felipealboy 0:be36515913f8 66 if(cont == 3){
felipealboy 0:be36515913f8 67 lcd.gotoxy(1,1);
MaikonJT 1:808bed0f2433 68 lcd.printf("Res.:% .0fohm ",resistencia);
MaikonJT 1:808bed0f2433 69 wait(0.2);
felipealboy 0:be36515913f8 70 }
MaikonJT 1:808bed0f2433 71
felipealboy 0:be36515913f8 72 }
felipealboy 0:be36515913f8 73 }