leplant grupo / Mbed 2 deprecated proejemploserieconpap

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tanofgennaro
Date:
Fri Oct 25 02:26:16 2019 +0000
Commit message:
commit inicial;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 27c2c0eb7c1d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 25 02:26:16 2019 +0000
@@ -0,0 +1,116 @@
+ #include "mbed.h"
+//Definimos que el puerto serie se llama pc
+Serial pc(USBTX, USBRX);
+//Variable donde se guarda lo leido
+char   c = '\0';
+//bit usado como flag para procesar datos
+bool newdata = false;   //Se pone en true cuando hay nuevos datos
+//Creamos los tres leds pra usar
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+
+DigitalOut MA1(PTB11);
+DigitalOut MA2(PTB10);
+DigitalOut MA3(PTB9);
+DigitalOut MA4(PTB8);
+
+//Callback cuando se detecta una entrada
+void onCharReceived(){
+    //Copiamos lo leido en c
+    c = pc.getc();
+    newdata = true;
+}
+int main()
+{
+//Apagamos los leds
+    /*
+    led1 = 1;
+    led2 = 1;
+    led3 = 1;
+    */
+//Ejecutar onCharReceived por cada entrada por puerto
+    pc.attach(&onCharReceived);
+    while (true)
+    {
+        if(newdata){
+            newdata = false;
+            printf("Recibimos '%c' \r\n",c);
+            switch(c){
+                case '1':
+                   printf("paso 0");
+                    MA1=0;   
+                    MA2=0;
+                    MA3=0;
+                    MA4=0;
+                    //Hacemos NULL c para que no vuelva a ejecutar
+                    c = '\0';
+                break;
+                case '2':
+                     printf("paso 2");
+                    MA1=1;   
+                    MA2=1;
+                    MA3=0;
+                    MA4=0;
+                    c = '\0';
+                break;
+                case '3':
+                   printf("paso 3");
+                    MA1=0;   
+                    MA2=1;
+                    MA3=0;
+                    MA4=0; 
+                    c = '\0';
+                break;
+                case '4':
+                     printf("paso 4");
+                     MA1=0;   
+                     MA2=1;
+                     MA3=1;
+                     MA4=0;
+                    c = '\0';
+                break;
+                case '5':
+                    printf("paso 5");
+                    MA1=0;   
+                    MA2=0;
+                    MA3=1;
+                    MA4=0;
+                    c = '\0';
+                break;
+                case '6':
+                    printf("paso 6");
+                    MA1=0;   
+                    MA2=0;
+                    MA3=1;
+                    MA4=1;
+                    c = '\0';
+                break;
+                case '7':
+                    printf("paso 7");
+                    MA1=0;   
+                    MA2=0;
+                    MA3=0;
+                    MA4=1;
+                    c = '\0';
+                break;
+                case '8':
+                printf("paso 8");
+                    MA1=1;   
+                    MA2=0;
+                    MA3=0;
+                    MA4=1;
+                    c = '\0';
+                break;
+                default:
+                printf("paso 0");
+                    MA1=0;   
+                    MA2=0;
+                    MA3=0;
+                    MA4=0;
+                    c = '\0';
+                break; 
+            }
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 27c2c0eb7c1d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 25 02:26:16 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file