Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //se carga la libreria ControlP5
- import controlP5.*;
- //se carga la libreria Serial
- import processing.serial.*;
- // definir la variable cp5 del tipo ControlP5
- ControlP5 cp5;
- // definir la variable puerto del tipo Serial
- Serial puerto;
- // definir la variable text del tipo Textfield
- Textfield text;
- void setup(){
- //tamaño de la ventana
- size(250,160);
- //se crea el objeto controlP5
- cp5 = new ControlP5(this);
- text = cp5.addTextfield("text")
- .setPosition(20,30)
- .setSize(200,40)
- .setFont(createFont("arial",20))
- .setAutoClear(false);
- cp5.addButton("Enviar")
- .setValue(1)
- .setPosition(20,100)
- .setSize(40,30)
- .setId(2);
- String COM = Serial.list()[0];
- //comunicacion serial a 9600bps
- puerto = new Serial(this, COM, 9600);
- }
- void draw(){
- background(#000000);
- }
- void controlEvent(ControlEvent theEvent){
- if(theEvent.isAssignableFrom(Button.class)){
- //se envia cada caracter de la cadena
- for(int i = 0; i < text.getText().length(); i++){
- char dato = text.getText().charAt(i);
- puerto.write(dato);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement