u

Dependencies:   TextLCD mbed

Revision:
0:c22b84cb23e7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jul 10 23:28:34 2014 +0000
@@ -0,0 +1,145 @@
+#include "mbed.h"
+#include "TextLCD.h"
+ TextLCD lcd(PTC16, PTC17, PTA16, PTA17, PTE31, PTD6); // rs, e, d4-d7
+
+DigitalIn sensor(PTE20);
+
+Ticker visualiza;
+Ticker cuenta;
+Ticker x;
+int vueltas, rpm;
+BusOut sentido_giro(D12, D13);
+DigitalIn bajar(D15);
+DigitalIn subir(D14);
+DigitalIn derecha(PTC12);
+DigitalIn izquierda(PTC13);
+PwmOut velocidad(D11);
+
+BusOut transistores(D0,D1);
+BusOut segmentos (A0,A1,A2,A3,A4,A5,PTE30);
+
+BusOut transistores2(D2, D3);
+BusOut segmentos2 (D4,D5,D6,D7, D8,D9, D10);  
+// tabla de segmentos
+const char seg[10] = {0x3f, 0x06,0x5b,0x57,0x66,0x75,0x7d,0x07,0x7f,0x77}; 
+char unidades,decenas, miliunidades, milidecenas;
+void segundo(){
+
+  vueltas = 0;
+  
+         miliunidades = rpm%10;
+        milidecenas = (rpm%100)/10;
+        unidades = (rpm/100)%10;
+        decenas = rpm/1000;  
+    }
+void cambio(){
+     static bool bandera;
+   bandera = !bandera;
+   switch (bandera){
+        case 0:
+        transistores = 0x0;
+              segmentos = seg[unidades];
+              transistores = 0x2;
+                            
+ transistores2 = 0x0;
+              segmentos2 = seg[miliunidades];
+              transistores2 = 0x2;
+              
+        break;
+        case 1: 
+         transistores = 0x0;
+              segmentos = seg[decenas];
+              transistores = 0x1;
+              
+              transistores2 = 0x0; 
+              segmentos2 = seg[milidecenas];
+              transistores2 = 0x1; 
+              
+              break;
+              }} 
+              unsigned int revol;
+             
+ int main() {
+     lcd.cls();
+     lcd.printf("  REVOLUCIONES ");
+    lcd.locate(1, 5);
+    lcd.printf("POR  MINUTO :)");
+ sentido_giro = 0x0;
+ velocidad = 0.15;
+ rpm = 0;  vueltas = 0;
+
+transistores = 0x0;
+transistores2 = 0x0;
+visualiza.attach(&cambio,0.008333); // tiempo de visualizacion
+
+    while(1) {
+     rpm = vueltas * 60;
+     
+     if (!derecha && izquierda){
+         wait (0.1);
+              if (derecha==0){
+                  lcd.cls();
+          lcd.printf("    izquierda   ");
+            lcd.locate(1, 5);
+    lcd.printf("               ");
+           sentido_giro = 0x1;
+                    }
+      } 
+      else if (derecha && !izquierda){
+           wait (0.1);
+           if (izquierda==0){
+           sentido_giro = 0x2;
+           lcd.cls();
+            lcd.printf("    Derecha    ");
+            lcd.locate(1, 5);
+            lcd.printf("               ");
+             }           
+             }
+            if (subir ==0 ){
+              wait (0.5);
+          velocidad = velocidad + 0.03;
+          lcd.cls();
+               lcd.printf(" Subiendo PWM ");
+            lcd.locate(1, 5);
+            lcd.printf   ("               ");
+            
+            unidades = 0;decenas = 0; miliunidades = 0; milidecenas  = 0;
+          if (velocidad >= 0.3) { 
+          velocidad = 0.3;
+                lcd.cls();
+                lcd.printf(" RPM maximo ");
+                 lcd.locate(1, 5);
+                    lcd.printf   ("               ");
+          } }
+          if (bajar ==0 ) {
+              wait(0.5); 
+          velocidad = velocidad - 0.03;
+          lcd.cls();
+           lcd.printf ("  Bajando PWM  ");
+            lcd.locate(1, 5);
+            lcd.printf("               ");
+            unidades = 0;decenas = 0; miliunidades = 0; milidecenas  = 0;
+           if (velocidad <= 0.0){
+             velocidad = 0.0; 
+            lcd.cls();
+                lcd.printf("  0 RPM  ");
+                 lcd.locate(1, 5);
+                    lcd.printf   ("               "); 
+           }}
+            
+           
+              if (!sensor){
+           wait (0.01);
+              if (sensor==1){
+                    vueltas = vueltas + 1;
+                   if (vueltas == 1)
+                   {
+                       x.attach(&segundo,1);
+          
+           
+                    }
+      } 
+            
+    
+      
+}  }}    
\ No newline at end of file