// LIBRERIAS
import controlP5.*;
import processing.serial.*;
// CREACION DE OBJETOS
ControlP5 cp5;
Serial serial;
Textlabel texto1, texto2, texto3, texto4, texto5, texto6; // definir las variables
// TAMAÑO TITULOS
PFont f;
boolean on_off = false;
//BOTONESl
Button envio;
Toggle actauto;
// SLIDERS
Slider movx, movy, movz;
// CAJAS INGRESO DE VALORES
Textfield textb, texth, textc;
// ARREGLO PARA MOTORES PASO A PASO
int MOTORX=0, MOTORY=1, MOTORZ=2;
int[] motor = new int[3];
int var=0;
void setup() {
size(450, 370);
background(40);
smooth();
// TITULOS
f = createFont("Arial", 12, true);
cp5 = new ControlP5(this);
serial = new Serial(this, Serial.list()[0], 9600);
// VALORES PREDETERMINADOS PARA LOS MOTORES
motor[MOTORX]=0;
motor[MOTORY]=0;
motor[MOTORZ]=0;
//BOTON ENVIAR AUTO
envio = cp5.addButton("envio", 1, 310, 125, 50, 20);
//TOGGLES PARA ACTIVAR MANDOS
actauto = cp5.addToggle("on_off", false, 53, 100, 26, 10);
// INPUT TEXTBOX BASE
textb = cp5.addTextfield("ejeX", 100, 125, 50, 20);
textb.setFocus(true);
// INPUT TEXTBOX HOMBRO
texth = cp5.addTextfield("ejeY", 170, 125, 50, 20);
texth.setFocus(true);
// INPUT TEXTBOX CODO
textc = cp5.addTextfield("ejeZ", 240, 125, 50, 20);
textc.setFocus(true);
// crear texto
texto1 = cp5.addTextlabel("label")
.setText("INTERFAZ CNC ANDI")
.setPosition(60, 30)
.setColorValue(0xffffffFF)
.setFont(createFont("Broadway", 30))
;
texto2 = cp5.addTextlabel("label1")
.setText("Introduzca las coordenadas en mm")
.setPosition(120, 170)
.setColorValue(0xffffffFF)
.setFont(createFont("arial", 12))
;
texto3 = cp5.addTextlabel("label2")
.setText("Encender el boton ON/OFF para inicializar el modulo")
.setPosition(80, 190)
.setColorValue(0xffffffFF)
.setFont(createFont("arial", 12))
;
// otra forma de crear texto
texto4 = new Textlabel(cp5, "Estudiante: Andres Felipe Sinisterra", 40, 280, 600, 200);
texto4.setFont(createFont("MV Boli", 15));
texto5 = new Textlabel(cp5, "Ingenieria Electronica", 40, 295, 600, 200);
texto5.setFont(createFont("MV Boli", 15));
texto6 = new Textlabel(cp5, "Decimo semestre", 40, 310, 600, 200);
texto6.setFont(createFont("MV Boli", 15));
}
//----------------------------------------------------------------------------------------------
void draw() {
background(20, 100, 200); // color de fondo de la ventana
texto4.draw(this); // introduce el texto en la ventana
texto5.draw(this);
texto6.draw(this);
textFont(f, 12);
fill(255);
text(" ---------------- MANDO AUTOMATICO -------------------------", 50, 105);
}
//-------------------FIN DEL LOOP---------------------------
// FUNCION DE EVENTOS
void controlEvent(ControlEvent theEvent) {
//if (theEvent.isController()) {
if ( on_off == true ) {
//while (var < 1) {
motor[0] = (int(textb.getText()));
motor[1] = (int(texth.getText()));
motor[2] = (int(textc.getText()));
if(theEvent.controller().name()=="envio") {
serial.write('M' + ":" + motor[0] + ":" + motor[1] + ":" + motor[2]); // envia por el puerto serial el nombre y el valor
println('M' + ":" + motor[0] + ":" + motor[1] + ":" + motor[2]); // imprime por pantalla el nombre y el valor
//var++;
}
}
// var=0;
// delay(100);
}