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
Fork of 10Funciones by
Diff: main.cpp
- Revision:
- 2:773082426491
- Parent:
- 1:a9b3fdab473e
--- a/main.cpp Tue Nov 21 20:05:14 2017 +0000
+++ b/main.cpp Fri Nov 24 21:19:29 2017 +0000
@@ -1,6 +1,9 @@
+//---------------------------------LIBRERIAS--------------------------------------------
#include "mbed.h"
#include "math.h"
#include "cstdlib"
+
+//--------------------------DECLARACON DE CONTANTES-------------------------------
#define MAXPOS 255
#define SS_TIME 500
#define POSDRAW 300
@@ -10,16 +13,18 @@
#define DEBUG 1
#define BUFF_POS 6
+//--------------------------DECLARACION DE PUERTOS I/O----------------------------
PwmOut myServoX(PB_3); //MOTOR EJE X
PwmOut myServoY(PB_4); //MOTOR EJE Y
PwmOut myServoZ(PB_10);//MOTOR EJE Z
+InterruptIn mybutton2(PA_0);
+InterruptIn mybutton(USER_BUTTON);
Serial command(USBTX, USBRX); //COMUNICACION SERIAL
-Serial Sdebug(USBTX, USBRX);
+Serial Sdebug(USBTX, USBRX);
DigitalOut led(LED1); //DECLARACION LED DE LA PLACA
-InterruptIn mybutton(USER_BUTTON);
-
-// COMANDOS
+
+//---------------------------DEFINICION COMANDOS POR CONSOLA----------------------
#define LED 0
#define PUNTO 1
#define LINE 2
@@ -32,15 +37,18 @@
#define HOME 9
#define TIEMPO_DE_PASO 10
-Ticker ticker1;
-Timeout timeout;
+//--------------------------LLAMADO RUTINA DE INTERRUPCIONES----------------------
+//Ticker ticker1; //Variable para rutina de interupciones
+//Timeout timeout;//Llamado de variable por conteo para manejo de pausa
-int rap;
+//-------------------------VARIABLES GLOBALES-------------------------------------
+int rap;//Pendiente
int RSTEP = 5;
double abajo=7;
double arriba=0;
double k,l,r,tp=50,paso=0;
int p=0;
+uint8_t estado = 0;
//*****************************************************************************
// COMANDO MOVER MOTOR
@@ -52,13 +60,12 @@
// <,> -> inicio, y fin de comando
// el inicio de comando no se almacena en el buffer
//*****************************************************************************
-// VARIABLES PARA DEFINIR EL COMMANDO
+//--------------------------DETERMINACION TAMAÑO DE BUFFER------------------------
uint8_t buffer_command[BUFF_SIZE]={0,0,0,0,0,0};
float buffer_POS [BUFF_POS]= {0,0,0,0,0,0};
-void savep();
-void interrupcion();
+//--------------------FUNCIONES PARA COMANDO DE BUFFER----------------------------
int coord2us(float coord)
{
@@ -123,7 +130,10 @@
uint8_t SSTIME = 100;
void tiempo_de_paso(int SST)
{
- SSTIME=SST;
+
+
+//-------------------------CONFIURACION SSTIME/VERTEX-----------------------------
+ SSTIME=SST;
#if DEBUG
command.printf("\nTiempo en pasos definida en:%i\n",SSTIME);
#endif
@@ -139,11 +149,12 @@
wait_ms(SSTIME);
}
+//--------------------------DECLARACION MEMORIA DE SERVOS-------------------------
uint8_t posx_old=0; // posición anterior del eje X
uint8_t posy_old=0; // posición anterior del eje Y
uint8_t posz_old=0; // posición anterior del eje Y
uint8_t ss_time=100; // tiempo de espera para moverse 1 mm en microsegundos
-
+//-------------------------VARIABLES SSTIME/RESOLUCION----------------------------
void put_sstime(uint8_t vtime){
ss_time=vtime;
}
@@ -174,6 +185,8 @@
command.printf("Resolucion definida en = %i \n", RSTEP);
#endif
}
+
+//---------------------------------FUNCION HOME-----------------------------------
void home()
{
vertex2d(0,0,0);
@@ -183,6 +196,8 @@
{
vertex2d(250,250,150);
}
+
+//---------------------------------FUNCION DOT-----------------------------------
void punto(uint8_t x, uint8_t y)
{
command.printf("Coord x= %i, coord y=%i \n",x,y);
@@ -195,6 +210,8 @@
home();
}
+
+//------------------------------FUNCION LINE--------------------------------------
void line(float xi, float xf, float yi, float yf)
{
// los parametros son coordenadas iniciales y finales de la linea en milimetros
@@ -212,8 +229,6 @@
{
yp =m*xp+b;
vertex2d(xp,yp,abajo);
- savep();
-
#if DEBUG
Sdebug.printf("coord X = %f,coord Y = %f \n", xp,yp);
#endif
@@ -221,6 +236,8 @@
nodraw();
home();
}
+
+//-----------------------------FUNCION RECTANGULO---------------------------------
void rectangle(uint8_t xi, uint8_t yi,uint8_t a, uint8_t h)
{
int x,y;
@@ -241,6 +258,8 @@
wait_ms(600);
home();
}
+
+ //-----------------------------FUNCION CIRCULO-----------------------------------
void circle(uint8_t x1, uint8_t y1,uint8_t r)
{
double x2,y2,i,j;
@@ -302,36 +321,27 @@
}
home();
}
-
-
-
- void savep(){
- for (uint8_t i=0; i<BUFF_POS;i++)
- {
- buffer_command[i]=command.getc();
-
- }
}
-
+//-------------------------------FUNCION REANUDAR---------------------------------
void reanudar(){
- led =0;
- p=0;
-
+ command.printf("piccolo reanudando \n");
+ wait (1);
+ return;
+
}
-
-
+//------------------------------FUNCION PAUSA------------------------------------
void pause(){
- timeout.attach(&pause, 0.5);
+ led = !led;
+ command.printf("piccolo en pausa \n");
wait (5);
-
-
-
-
+ return;
+
}
-
+
+//-------------------------------FUNCION PARE-------------------------------------
void stop() //Funcion para detener el programa
{
exit(0);
@@ -340,6 +350,8 @@
void command_exe()
{
+
+//-------------------------ASIGNACION EN SWTICH CASE------------------------------
#if DEBUG
command.printf("Ejecutando comando: ");
#endif
@@ -430,15 +442,33 @@
}
}
-
- void interrupcion(){
+//--------------------------***PENDIENTE***---------------------------------------
+ void Rx_interrupcion(){
+
+ char p = command.getc();
+
+ command.printf("picolo en pausa %c\n",p);
+ wait_ms(2000);
+ return ;
+
+ }
+
+
+//----------------------------------MAIN DE PROGRAMA------------------------------
+int main() {
+ #if DEBUG
+ command.printf("inicio con debug\n");
+ #else
+ command.printf("inicio sin debug\n");
+ #endif
uint8_t val;
// mybutton.rise(&stop);
while(1){
val=command.getc();
if (val== '<'){
Read_command();
- mybutton.rise(&pause);
+ mybutton.fall(&pause);
+ mybutton.rise(&reanudar);
if (check_command()){
command_exe();
}
@@ -457,24 +487,7 @@
}
}
- }
-
-
-
-
-
-
-
-int main() {
- #if DEBUG
- command.printf("inicio con debug\n");
- #else
- command.printf("inicio sin debug\n");
- #endif
- ticker1.attach(&interrupcion,0.5);
- for(;;);
-
-
+
}
