Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //se carga la libreria ControlP5
  2. import controlP5.*;
  3. //se carga la libreria Serial
  4. import processing.serial.*;
  5. // definir la variable cp5 del tipo ControlP5
  6. ControlP5 cp5;
  7. // definir la variable puerto del tipo Serial
  8. Serial puerto;
  9. // definir la variable text del tipo Textfield
  10. Textfield text;
  11.  
  12. void setup(){
  13. //tamaƱo de la ventana
  14. size(250,160);
  15.  
  16. //se crea el objeto controlP5
  17. cp5 = new ControlP5(this);
  18.  
  19. text = cp5.addTextfield("text")
  20. .setPosition(20,30)
  21. .setSize(200,40)
  22. .setFont(createFont("arial",20))
  23. .setAutoClear(false);
  24.  
  25. cp5.addButton("Enviar")
  26. .setValue(1)
  27. .setPosition(20,100)
  28. .setSize(40,30)
  29. .setId(2);
  30.  
  31. String COM = Serial.list()[0];
  32. //comunicacion serial a 9600bps
  33. puerto = new Serial(this, COM, 9600);
  34. }
  35.  
  36. void draw(){
  37. background(#000000);
  38. }
  39.  
  40. void controlEvent(ControlEvent theEvent){
  41. if(theEvent.isAssignableFrom(Button.class)){
  42. //se envia cada caracter de la cadena
  43. for(int i = 0; i < text.getText().length(); i++){
  44. char dato = text.getText().charAt(i);
  45. puerto.write(dato);
  46. }
  47. }
  48. }