/*
Crhistian David Lucumi
Sistemas Embebidos
Laboratorio 9
*/
import processing.serial.*;
import controlP5.*;
ControlP5 cp5;
Textarea myTextarea;
String textValue = "";
Serial serie;
void setup() {
size(700,400);
PFont font = createFont("arial",20);
cp5 = new ControlP5(this);
cp5.addTextfield("input")
.setPosition(20,100)
.setSize(200,40)
.setFont(font)
.setFocus(true)
.setColor(color(255,0,0))
;
cp5.addBang("clear")
.setPosition(240,170)
.setSize(80,40)
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
;
myTextarea = cp5.addTextarea("txt")
.setPosition(20,70)
.setSize(200,20)
.setFont(createFont("arial",12))
.setLineHeight(14)
.setColor(color(128))
.setColorBackground(color(255,100))
.setColorForeground(color(255,100));
;
myTextarea.setText("Solo Letras de la A-Z y Numeros Positivos"
);
serie = new Serial(this, Serial.list()[0], 9600);
textFont(font);
}
void draw() {
background(0);
fill(255);
text(cp5.get(Textfield.class,"input").getText(), 360,130);
text(textValue, 360,180);
}
public void clear() {
cp5.get(Textfield.class,"input").clear();
}
void controlEvent(ControlEvent theEvent) {
if(theEvent.isAssignableFrom(Textfield.class)) {
serie.write( ""+theEvent.getStringValue() );
}
}