Dependencies:   mbed

Revision:
0:7efa0deeaf7a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jul 10 23:26:54 2014 +0000
@@ -0,0 +1,118 @@
+#include "mbed.h"
+
+Ticker visualiza;
+Ticker cuenta;
+DigitalIn pulsador(D11);
+
+DigitalOut led_rojo(LED1);
+DigitalOut pin0(A0);
+DigitalOut pin1(A1);DigitalOut pin2(A2);DigitalOut pin3(A3);DigitalOut pin4(A4);DigitalOut pin5(A5);DigitalOut pin6(PTE30);
+DigitalOut pin7(D4); DigitalOut pin8(D5); DigitalOut pin9(D6);DigitalOut pin10(D7);DigitalOut pin11(D8);DigitalOut pin12(D9);DigitalOut pin13(D10);
+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,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
+const char seg2[10] = {0x6f, 0x7f, 0x07,0x7d, 0x6d,0x66,0x4f,0x5b,0x06,0x3f}; 
+char unidades,decenas, miliunidades, milidecenas;
+void cambio(){
+      static bool bandera;
+   bandera = !bandera;
+  
+     if (bandera){
+              segmentos = seg[unidades];
+              transistores = 0x2;
+              segmentos2 = seg[miliunidades];
+              transistores2 = 0x2;
+              } 
+         else  {
+              segmentos = seg[decenas];
+              transistores = 0x1;
+             segmentos2 = seg[milidecenas];
+              transistores2 = 0x1; } 
+               
+
+               }
+void retroceso (){
+     static bool bandera2;
+   bandera2 = !bandera2;
+  
+     if (bandera2){
+              segmentos = seg2[unidades];
+              transistores = 0x2;
+              segmentos2 = seg2[miliunidades];
+              transistores2 = 0x2;
+              } 
+         else  {
+              segmentos = seg2[decenas];
+              transistores = 0x1;   
+              segmentos2 = seg2[milidecenas];
+              transistores2 = 0x1; }  
+   }
+void conteo (){
+        
+        miliunidades++;
+        if (miliunidades > 9) 
+           {milidecenas++; miliunidades =0;}
+        if (milidecenas > 9)
+           {unidades++; milidecenas =0;}
+             if (unidades > 9) 
+            {decenas++; unidades = 0;}
+             if (decenas > 9) 
+            {     
+miliunidades = 0;
+milidecenas = 0;
+unidades = 0;
+decenas = 0;  
+transistores = 0x3; transistores2 = 0x3; led_rojo = 0; wait (0.2);
+transistores = 0x0; transistores2 = 0x0; led_rojo = 1;wait (0.2);
+transistores = 0x3; transistores2 = 0x3; led_rojo = 0;wait (0.2);
+transistores = 0x0; transistores2 = 0x0; led_rojo = 1;wait (0.2);
+transistores = 0x3; transistores2 = 0x3; led_rojo = 0;wait (0.2);
+transistores = 0x0; transistores2 = 0x0; led_rojo = 1;wait (0.2); 
+/*transistores = 0x3; transistores2 = 0x3;led_rojo = 0;pin0 = 1; pin1 = 1;pin2 = 1;pin3 = 1;pin4 = 1;pin5 = 1;pin6 = 1;pin7 = 1;pin8 = 1;pin9 = 1; pin10 = 1;pin11 = 1;pin12 = 1;pin13 = 1; wait(0.2);
+transistores = 0x0; transistores2 = 0x0;led_rojo = 1; pin0 = 0; pin1 = 0;pin2 = 0;pin3 = 0;pin4 = 0;pin5 = 0;pin6 = 0;pin7 = 0;pin8 = 0;pin9 = 0; pin10 = 0;pin11 = 0;pin12 = 0;pin13 = 0; wait(0.2);
+
+transistores = 0x3; transistores2 = 0x3;led_rojo = 0;pin0 = 1; pin1 = 1;pin2 = 1;pin3 = 1;pin4 = 1;pin5 = 1;pin6 = 1;pin7 = 1;pin8 = 1;pin9 = 1; pin10 = 1;pin11 = 1;pin12 = 1;pin13 = 1; wait(0.2);
+transistores = 0x0; transistores2 = 0x0;led_rojo = 1; pin0 = 0; pin1 = 0;pin2 = 0;pin3 = 0;pin4 = 0;pin5 = 0;pin6 = 0;pin7 = 0;pin8 = 0;pin9 = 0; pin10 = 0;pin11 = 0;pin12 = 0;pin13 = 0; wait(0.2);
+
+transistores = 0x3; transistores2 = 0x3;led_rojo = 0;pin0 = 1; pin1 = 1;pin2 = 1;pin3 = 1;pin4 = 1;pin5 = 1;pin6 = 1;pin7 = 1;pin8 = 1;pin9 = 1; pin10 = 1;pin11 = 1;pin12 = 1;pin13 = 1; wait(0.2);
+transistores = 0x0; transistores2 = 0x0;led_rojo = 1;pin0 = 0; pin1 = 0;pin2 = 0;pin3 = 0;pin4 = 0;pin5 = 0;pin6 = 0;pin7 = 0;pin8 = 0;pin9 = 0; pin10 = 0;pin11 = 0;pin12 = 0;pin13 = 0; wait(0.2);*/
+ 
+}
+}
+
+int main(void)
+{
+transistores = 0x0;          
+transistores2 = 0x0;
+led_rojo = 1;
+
+
+  while(1){
+ 
+    if (pulsador==0){
+        wait (0.8);
+        miliunidades = 0;
+        milidecenas = 0;
+        unidades = 0;
+        decenas = 0;
+   cuenta.attach(&conteo,0.01);
+visualiza.attach(&cambio,0.008333);
+
+ } 
+ if (pulsador==0){
+        wait (0.8);
+        miliunidades = 0;
+        milidecenas = 0;
+        unidades = 0;
+        decenas = 0;
+     
+    cuenta.attach(&conteo,0.01);
+visualiza.attach(&retroceso,0.008333);
+
+ }
+ } } 
+
+