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:
- 25:8aaf4f9111fe
- Parent:
- 24:7f14b70fc9ef
--- a/main.cpp Mon Apr 08 11:03:25 2019 +0100
+++ b/main.cpp Mon Jul 20 20:32:35 2020 +0000
@@ -1,12 +1,110 @@
#include "mbed.h"
+#include "stdlib.h"
+#define tam_men 4
+Ticker t_motor;
+//Serial
+Serial pc(USBTX, USBRX);
+//puertos
+BusOut bobinas(D7, D6,D5,D4);
+DigitalOut a(D8);
+DigitalOut b(D9);
+PwmOut pwm(PTE29);
+//Variables
+int ii=0;
+float motor;
+float duty_led;
+float motor_dc;
+float servomotor;
+float paso;
+char men[tam_men];
+char cadena[tam_men-1];
+char c;
+int i=0, x=0;
+int bandera;
+//tabla de la secuencia de pasos
+//char const sec[8]={0x1, 0x3, 0x2, 0x6, 0x4, 0xc, 0x8, 0x9};
+char const sec[4]={0x1, 0x2, 0x4, 0x9};
+//metodos
+void recibir();
+void rc_isr();
+void mover_motor();
-DigitalOut myled(LED1);
+void rc_isr()
+{
+ pc.attach(NULL, Serial::RxIrq);
+ recibir();
+
+}
+void recibir()
+{
+
+ c = pc.getc(); // Read hyperterminal
+ // pc.putc(c);
+ if(c=='a'){bandera=1;}
+ else if(c=='b'){bandera=2;}
+ else if(c=='c'){bandera=3;}
+ else if ((c != '\r') & (i < tam_men))
+ {
+ if ( (c >= '0') & (c <= '9') )
+ {
+ men[i] = c;
+ i++;
+ }
+ else
+ {
+ if(bandera==1){
+ motor_dc = atof(men);
+ a=1;
+ b=0;
+ motor=motor_dc*0.01;
+ pwm.write(motor);
+ pc.printf("motor dc %d \n\r",motor_dc);
+ }
+ else if(bandera==2){
+ servomotor = atof(men);
+ pc.printf("servo %d \n\r",servomotor);
+ }
+ else if(bandera==3){
+ paso = atof(men);
+ pc.printf("paso %d \n\r",paso);
+ }
+ for (i=0; i< tam_men; i++) {men[i] = '\0';}
+ i=0;
+ }
+ }
+ pc.attach(&rc_isr, Serial::RxIrq);
+}
+/*
+void motores() {
+ #include "mbed.h"
-int main() {
+//prototipos
+void mover_motor()
+{
+ bobinas= sec[i];
+ i++;
+ if(i==4) i=0;
+}
+int main (){
+ a=1;
+ b=0;
+ pwm.write(0.2f);
+ t_motor.attach(&mover_motor, 0.005);
+ while(true){
+
+ }
+ }
+
+ }
+
+*/
+int main()
+{
+ pc.attach(&rc_isr, Serial::RxIrq);
+ pc.printf("Comienzo...\n\r");
+ //led.period(8.33333e-3);
while(1) {
- myled = 1;
- wait(0.2);
- myled = 0;
- wait(0.2);
+ pc.printf("Esperando...\n\r");
+ wait(2);
}
-}
+}
\ No newline at end of file