ccvcv

Dependencies:   TextLCD mbed

Fork of PRACTICA3 by compartido

Revision:
4:71a955ddc240
Parent:
3:30f1e2f8308c
Child:
5:18feff1607c9
--- a/main.cpp	Fri Nov 10 12:54:55 2017 +0000
+++ b/main.cpp	Fri Nov 10 13:05:19 2017 +0000
@@ -4,7 +4,7 @@
 #define constante (3,3^2)/((2^16)-1)*100) // valor constante para el cálculo de Vrms
 #define vector 100      // valor para definir el tamaño de los búfferes de muestreo
 
-//TextLCD (6 puertos, TextLCD::LCD16x2); rs,e,d4-d7
+//TextLCD lcd(6 puertos, TextLCD::LCD16x2); rs,e,d4-d7
 InterruptIn Sw ();      //pulsador en el puerto
 AnalogIn leer ();       // leer del puerto
 Ticker muestreo;
@@ -13,12 +13,12 @@
 int contm=0;
 int contvpp=0;
 int dato=0,             // variable para seleccionar el dato a mostrar
-int bufferlleno=0;      // variable de estado
 int flag1;              // variable para indicar cuando se tiene que cambiar de buffer
 int flag2;              // variable para indicar cuando se tiene que
 int flag3;              // variable para indicar cuando se tiene que calcular Vpp
+int flag4;              // variable para indicar cuando se llena el buffer
 int Vpmax=0;            // variable para guardar el valor del pico superior
-int Vpmin=0;            // variable para guardar el valor del pico inferior 
+int Vpmin=0;            // variable para guardar el valor del pico inferior
 int Vpp=0;
 float buffer1 [vector]; // buffer de muestreo 1 de tamaño 100
 float buffer2 [vector]; // buffer de muestreo 2 de tamaño 100
@@ -49,44 +49,47 @@
     }
 }
 
-void LCD()
-{
-    lcd.cls();
-    switch (dato) {
-        case 0;
-            lcdprintf("Vrms: %n V",Vrms); //Vrms :\n%3.3f V,Vrms
-            break;
-        case 1;
-            lcdprintf("Vpp: %n V",Vpp); //
-            break;
-    }
-}
+//void LCD()
+//{
+//    lcd.cls();
+//    switch (dato) {
+//        case 0:
+//            lcdprintf("Vrms: %n V",Vrms); //Vrms :\n%3.3f V,Vrms
+//            break;
+//        case 1:
+//            lcdprintf("Vpp: %n V",Vpp); //
+//            break;
+//    }
+//}
 
 void calculovpp ()
 {
-    for(contvpp=0; contvpp=99; contvpp++)
+    for(contvpp=0; contvpp=99; contvpp++) {
         if (muestra(contvpp)>Vpmax) {
             Vpmax=muestra(contvpp);
         } else {
             if (muestra(contvpp)<Vpmin) {
                 Vpmin=muestra(contvpp);
-            } else {
-                if(!flag3) {
-                    Vpp = Vpmax-Vpmin;
-                    flag3=!flag3;
-                }
             }
         }
+        else {
+            if(!flag3) {
+                Vpp = Vpmax-Vpmin;
+                flag3=!flag3;
+            }
+        }
+    }
 }
 
 void calculovrms ()
 {
-for (contvrms=0; contvrms=99; contvrms++)
-{valor = muestra(contvrms);
-valor = valor*valor;
-sumatorio = sumatorio + valor;}
-Vrms = (constante*sumatorio)^(0.5);
+    for (contvrms=0; contvrms=99; contvrms++) {
+        valor = muestra(contvrms);
+        valor = valor*valor;
+        sumatorio = sumatorio + valor;
     }
+    Vrms = (constante*sumatorio)^(0.5);
+}
 
 int main()
 {
@@ -97,10 +100,12 @@
     //printf("pwm set to %.2f %%\n", mypwm.read() * 100);
 
     while(1) {
-        if (bufferlleno) {
-            suma=0;
+        if (flag4) {
+            valor=0;
+            sumatorio=0;
+
             flag3=0;
-            for (contm=0; contm<100: contm++) {
+for (contm=0; contm=99: contm++) {
                 if (flag1==1) {
                     muestra=buffer1[contm];
                 } else {