Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // LIBRERIAS
  2. import controlP5.*;    
  3. import processing.serial.*;
  4.  
  5. // CREACION DE OBJETOS
  6. ControlP5 cp5;  
  7. Serial serial;
  8.  
  9. Textlabel texto1, texto2, texto3, texto4, texto5, texto6; // definir las variables
  10.  
  11. // TAMAÑO TITULOS
  12. PFont f;
  13.  
  14. boolean on_off = false;
  15.  
  16.  
  17. //BOTONESl
  18. Button envio;
  19.  
  20. Toggle actauto;
  21.  
  22. // SLIDERS
  23. Slider movx, movy, movz;
  24.  
  25. // CAJAS INGRESO DE VALORES
  26. Textfield textb, texth, textc;
  27.  
  28. // ARREGLO PARA MOTORES PASO A PASO
  29. int MOTORX=0, MOTORY=1, MOTORZ=2;
  30. int[] motor = new int[3];
  31. int var=0;
  32.  
  33. void setup() {
  34.   size(450, 370);
  35.   background(40);
  36.   smooth();
  37.  
  38.   // TITULOS
  39.   f = createFont("Arial", 12, true);
  40.  
  41.   cp5 = new ControlP5(this);
  42.   serial = new Serial(this, Serial.list()[0], 9600);
  43.  
  44.   // VALORES PREDETERMINADOS PARA LOS MOTORES
  45.    motor[MOTORX]=0;        
  46.    motor[MOTORY]=0;
  47.    motor[MOTORZ]=0;
  48.  
  49.   //BOTON ENVIAR AUTO
  50.   envio =  cp5.addButton("envio", 1, 310, 125, 50, 20);
  51.  
  52.  
  53.   //TOGGLES PARA ACTIVAR MANDOS
  54.   actauto =  cp5.addToggle("on_off", false, 53, 100, 26, 10);
  55.  
  56.  
  57.   // INPUT TEXTBOX BASE
  58.   textb =  cp5.addTextfield("ejeX", 100, 125, 50, 20);
  59.   textb.setFocus(true);
  60.  
  61.   // INPUT TEXTBOX HOMBRO
  62.   texth =  cp5.addTextfield("ejeY", 170, 125, 50, 20);
  63.   texth.setFocus(true);
  64.  
  65.   // INPUT TEXTBOX CODO
  66.   textc =  cp5.addTextfield("ejeZ", 240, 125, 50, 20);
  67.   textc.setFocus(true);
  68.  
  69.   // crear texto
  70.   texto1 = cp5.addTextlabel("label")
  71.     .setText("INTERFAZ CNC ANDI")
  72.       .setPosition(60, 30)
  73.         .setColorValue(0xffffffFF)
  74.           .setFont(createFont("Broadway", 30))
  75.             ;
  76.  
  77.   texto2 = cp5.addTextlabel("label1")
  78.     .setText("Introduzca las coordenadas en mm")
  79.       .setPosition(120, 170)
  80.         .setColorValue(0xffffffFF)
  81.           .setFont(createFont("arial", 12))
  82.             ;
  83.  
  84.   texto3 = cp5.addTextlabel("label2")
  85.     .setText("Encender el boton ON/OFF para inicializar el modulo")
  86.       .setPosition(80, 190)
  87.         .setColorValue(0xffffffFF)
  88.           .setFont(createFont("arial", 12))
  89.             ;
  90.  
  91.   // otra forma de crear texto
  92.   texto4 = new Textlabel(cp5, "Estudiante: Andres Felipe Sinisterra", 40, 280, 600, 200);  
  93.   texto4.setFont(createFont("MV Boli", 15));
  94.   texto5 = new Textlabel(cp5, "Ingenieria Electronica", 40, 295, 600, 200);  
  95.   texto5.setFont(createFont("MV Boli", 15));
  96.   texto6 = new Textlabel(cp5, "Decimo semestre", 40, 310, 600, 200);  
  97.   texto6.setFont(createFont("MV Boli", 15));
  98. }
  99.  
  100.  
  101.  
  102. //----------------------------------------------------------------------------------------------
  103.  
  104. void draw() {
  105.  
  106.   background(20, 100, 200);  // color de fondo de la ventana
  107.   texto4.draw(this);    // introduce el texto en la ventana
  108.   texto5.draw(this);
  109.   texto6.draw(this);
  110.  
  111.   textFont(f, 12);  
  112.   fill(255);                        
  113.   text("            ---------------- MANDO AUTOMATICO -------------------------", 50, 105);
  114.  
  115. }
  116. //-------------------FIN DEL LOOP---------------------------
  117.  
  118. // FUNCION DE EVENTOS
  119. void controlEvent(ControlEvent theEvent) {
  120.   //if (theEvent.isController()) {
  121.  
  122.  
  123.     if ( on_off == true ) {
  124.       //while (var < 1) {      
  125.          motor[0] = (int(textb.getText()));
  126.          motor[1] = (int(texth.getText()));
  127.          motor[2] = (int(textc.getText()));
  128.        
  129.         if(theEvent.controller().name()=="envio") {
  130.           serial.write('M' + ":" + motor[0] + ":" + motor[1]  + ":" + motor[2]);   // envia por el puerto serial el nombre y el valor
  131.           println('M' + ":" + motor[0] + ":" + motor[1]  + ":" + motor[2]);    // imprime por pantalla el nombre y el valor
  132.           //var++;
  133.         }
  134.        
  135.       }
  136.      // var=0;
  137.      // delay(100);
  138.     }