Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:27c2c0eb7c1d
--- /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