Enrico Aloisi Nardi / Mbed 2 deprecated conversor_dac

Dependencies:   mbed

Revision:
5:436b7d88a92d
Parent:
4:76d5fb3100a3
Child:
6:e8afe3e31edb
--- a/conversor.cpp	Mon Jun 08 14:38:23 2020 +0000
+++ b/conversor.cpp	Mon Jun 08 14:47:42 2020 +0000
@@ -6,6 +6,7 @@
 
 Serial pc(USBTX, USBRX);
 float valor;
+int estado_botao;
 
 int SEQUENCIA[8]={
     0b000,
@@ -19,17 +20,51 @@
     };
 
 int main(){
+    estado_botao=0;
     pc.baud(9600);
     pc.printf("\r");
     pc.printf("oi");
     while(1){
-        for (int i=0; i<8; i++) {    
-        saida_digital = SEQUENCIA[i];
-        valor=leitura_an.read();
-        //valor = 3.3*leitura_an.read(); //conversão propriamente dita
-        pc.printf("\r\t%1.3f\n", valor);
-        wait(0.5);
+        if (botao_usuario == 0){ //Onda quadrada
+            if (botao_usuario < 4){
+                estado_botao++;
+            }
+            else{
+                estado_botao = 0;
+            }
+        }
+        if(estado_botao == 0){
+            for (int i=0; i<8; i++) { 
+            saida_digital = 0b111;
+            valor=leitura_an.read(); 
+            pc.printf("\r\t%1.3f\n",valor);  
+            wait(0.5);
+            saida_digital = 0b000;
+            }
         }
+        else if (estado_botao == 1){ //Onda rampa
+            for (int i=0; i<8; i++) { 
+            saida_digital = SEQUENCIA[i];
+            valor=leitura_an.read(); 
+            pc.printf("\r\t%1.3f\n",valor);  
+            wait(0.5);
+            }
+        }
+        else if (estado_botao == 2){ //Onda triangular
+            for (int i=0; i<8; i++) {    
+                saida_digital = SEQUENCIA[i];
+                wait(0.5);
+                valor=leitura_an.read();
+                pc.printf("\r\t%1.3f\n",i);    
+            }
+            for (int i=8; i>0; i--) {  
+                saida_digital = SEQUENCIA[i];
+                wait(0.5);
+                valor=leitura_an.read();
+                pc.printf("\r\t%1.3f\n",i);   
+            }
+        }
+        
         
     }
 }