Multímetro

Dependencies:   mbed LCDLib

Revision:
0:be36515913f8
Child:
1:808bed0f2433
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 13 14:34:19 2019 +0000
@@ -0,0 +1,68 @@
+#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);
+
+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 tensao;
+    int cont;
+    cont = 1;
+    //button1.mode(PullUp); // Activate pull-up
+    botao.fall(callback(botao_onpressed_cb)); // Attach ISR to handle button press event
+
+    while(1) {
+        
+        tensao = 3.3*adc.read();
+        
+        if (botao_pressed == true) { // Set when button is pressed
+            botao_pressed = false;
+            cont = cont++;        
+            led1 = !led1;
+        }
+        if(cont == 5){
+            cont = 1;    
+        }
+        if(cont == 1){
+            lcd.gotoxy(1,1);
+            lcd.printf("Tensao: %.2fV       ",tensao);
+        }
+        if(cont == 2){
+            lcd.gotoxy(1,1);
+            lcd.printf("Corrente: %.2fA       ",tensao);
+        }
+        if(cont == 3){
+            lcd.gotoxy(1,1);
+            lcd.printf("Resist.:% .2fohm",tensao);
+        }   
+        if(cont == 4){
+            lcd.gotoxy(1,1);
+            lcd.printf("Freq.:% .2fHz    ",tensao);
+        } 
+    }
+}