Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import controlP5.*;
- import processing.serial.*;
- Serial serie;
- ControlP5 cp5;
- int hum_alerta = 1023;
- void setup() {
- println(Serial.list());
- serie = new Serial(this, Serial.list()[0], 9600);
- //serie = new Serial(this, "COM19", 9600);
- cp5 = new ControlP5(this);
- size(400, 300);
- cp5.addTextlabel("title")
- .setText("Monitor de temperatura y humedad")
- .setPosition(10,10)
- .setColorValue(0xffffff00)
- .setFont(createFont("Georgia",20))
- ;
- cp5.addTextfield("Temperatura")
- .setPosition(20, 60)
- .setSize(200, 40)
- .setFocus(true)
- .setColor(color(255, 0, 0))
- ;
- cp5.addSlider("Temp")
- .setPosition(350, 60)
- .setSize(30, 200)
- .setRange(0, 200)
- .setValue(128)
- ;
- cp5.getController("Temp").getValueLabel().align(ControlP5.CENTER, ControlP5.TOP_OUTSIDE).setPaddingY(0);
- cp5.getController("Temp").getCaptionLabel().align(ControlP5.CENTER, ControlP5.BOTTOM_OUTSIDE).setPaddingY(0);
- //cp5.getController("Temp").setColorCaptionLabel(0);
- cp5.addTextfield("Humedad")
- .setPosition(20, 120)
- .setSize(200, 40)
- .setFocus(true)
- .setColor(color(255, 0, 0))
- ;
- cp5.addTextfield("Humedad_Tierra")
- .setPosition(20, 180)
- .setSize(200, 40)
- .setFocus(true)
- .setColor(color(255, 0, 0))
- ;
- cp5.addTextlabel("label")
- .setPosition(240, 180)
- .setText("Avisar humedad en tierra")
- .setColor(color(255, 0, 0))
- ;
- cp5.addTextfield("avisar_humedad")
- .setPosition(240, 200)
- .setSize(80, 40)
- .setFocus(true)
- .setColor(color(255, 0, 0))
- ;
- }
- void draw() {
- background(0);
- if (serie.available()>0) {
- char id_dato = serie.readChar();
- String dato = readstring();
- if (id_dato == 'T') {
- cp5.get(Textfield.class, "Temperatura").setText(dato+"ΒΊC");
- if (dato.length()<7) {
- cp5.get(Slider.class, "Temp").setValue(parseInt(dato.trim()));
- //println(dato+" "+(dato.length()));
- }
- } if (id_dato == 'H') {
- cp5.get(Textfield.class, "Humedad").setText(dato+"%");
- } if (id_dato == 'E') {
- //cp5.get(Textfield.class,"input").setText(dato);
- } if (id_dato == 'L') {
- cp5.get(Textfield.class, "Humedad_Tierra").setText(dato);
- if(dato.trim().length()<5&& parseInt(dato.trim())>=hum_alerta){
- println("Esta Seca");
- }
- }
- }
- }
- String readstring() {
- char dato = serie.readChar();
- String d = "";
- long s = millis();
- while (dato != '\n' && ((millis()-s)<=10)) {
- d+=dato;
- dato = serie.readChar();
- //delay(5);
- }
- return d;
- }
- public void avisar_humedad(String v) {
- hum_alerta = parseInt(v);
- println(v);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement