PROJETO

Dependencies:   mbed LCDLib

Committer:
MaikonJT
Date:
Thu Jul 04 13:36:33 2019 +0000
Revision:
2:efdd27c5c2c9
Parent:
1:808bed0f2433
PROJETO ARLINDO

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