Practica_6_-_Ejercicio_05

Dependencies:   mbed TextLCD Keypad

Files at this revision

API Documentation at this revision

Comitter:
isaacross99
Date:
Wed Nov 20 05:05:29 2019 +0000
Parent:
31:080589c1250a
Commit message:
0

Changed in this revision

Keypad.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keypad.lib	Wed Nov 20 05:05:29 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/grantphillips/code/Keypad/#4bbd88022a6f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Nov 20 05:05:29 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
--- a/main.cpp	Thu Oct 31 04:24:48 2019 +0000
+++ b/main.cpp	Wed Nov 20 05:05:29 2019 +0000
@@ -1,39 +1,77 @@
 #include "mbed.h"
-Serial pc(USBTX,USBRX);
-DigitalOut led0(PTD0); //Octavo pin (a partir del botón de RESET).
-DigitalOut led1(PTC4); //Noveno pin.
-DigitalOut led2(PTC12); //Decimo pin.
-DigitalOut led3(PTC3); //Onceavo pin (inicia en el nuevo carril). 
-Timer crono;
+#include "TextLCD.h"
+#include "Keypad.h"
+TextLCD lcd(PTE24, PTE25, PTD1, PTD3, PTD2, PTD0, TextLCD::LCD16x2); // rs, e, d4-d7
+Keypad kpad(PTA2, PTB23, PTA1, PTB9, PTC4, PTC12, PTC3, PTC2);
+DigitalIn borrador(PTC17);
+DigitalOut led(PTC16);
+int main() {
+    char key, memoria = '.';
+    int released = 1, contador = 0;
+    led = 0;
+    while(1){
+        if(borrador){ //Testear la dualidad del botón borrador con el ejercicio 3.
+            lcd.cls();
+            led = 0;
+            contador = 0;
+        }
+        else{
+            key = kpad.ReadKey();                   //read the current key pressed
 
-int main(){
-    led0 = 1;
-    led1 = 1;
-    led2 = 1;
-    led3 = 1;
-    crono.start();
-    for(int i; i < 50; i++){ // Dado que la resolución es de 1.8 grados, se necesitan 200 pasos para completar un giro.
-        led0 = 0;
-        led1 = 1;
-        led2 = 0;
-        led3 = 1;
-        wait(0.025‬‬);
-        led0 = 0;
-        led1 = 1;
-        led2 = 1;
-        led3 = 0;
-        wait(0.025‬);
-        led0 = 1;
-        led1 = 0;
-        led2 = 1;
-        led3 = 0;
-        wait(0.025‬);
-        led0 = 1;
-        led1 = 0;
-        led2 = 0;
-        led3 = 1;
-        wait(0.025‬);
+        if(key == '\0')
+            released = 1;                       //set the flag when all keys are released
+           
+        if((key != '\0') && (released == 1)) {  //if a key is pressed AND previous key was release
+            lcd.cls();
+            switch(key){
+                case '0': lcd.printf("00000000 ");
+                break;
+                case '1': lcd.printf("00000001 ");
+                break;
+                case '2': lcd.printf("00000010 ");
+                break;
+                case '3': lcd.printf("00000011 ");
+                break;
+                case '4': lcd.printf("00000100 ");
+                break;
+                case '5': lcd.printf("00000101 ");
+                break;
+                case '6': lcd.printf("00000110 ");
+                break;
+                case '7': lcd.printf("00000111 ");
+                break;
+                case '8': lcd.printf("00001000 ");
+                break;
+                case '9': lcd.printf("00001001 ");
+                break;
+                case 'A': lcd.printf("00001010 ");
+                break;
+                case 'B': lcd.printf("00001011 ");
+                break;
+                case 'C': lcd.printf("00001100 ");
+                break;
+                case 'D': lcd.printf("00001101 ");
+                break;
+                default: lcd.printf("%c", key);
+            }
+            
+            if(memoria == key)
+                contador = contador + 1;
+            else
+                contador = 0;
+            
+            if(contador > 0){
+                lcd.cls();
+                lcd.printf("\n%c = %d", key, contador);
+            }
+            
+            if(contador == 10){
+                led = 1;
+            }
+            
+            memoria = key;
+            released = 0;                       //clear the flag to indicate that key is still pressed
+        }
+        }
     }
-    crono.stop();
-    pc.printf("Tiempo de giro: %f seg", crono.read());
 }
\ No newline at end of file