Advertisement
CDLM0721

Monitor humedad y termperatura pde

Dec 11th, 2017
2,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1. import controlP5.*;
  2.  
  3. import processing.serial.*;
  4.  
  5.  
  6. Serial serie;
  7. ControlP5 cp5;
  8. int hum_alerta = 1023;
  9. void setup() {
  10.  
  11.   println(Serial.list());
  12.   serie = new Serial(this, Serial.list()[0], 9600);
  13.   //serie = new Serial(this, "COM19", 9600);
  14.   cp5 = new ControlP5(this);
  15.   size(400, 300);
  16.   cp5.addTextlabel("title")
  17.                     .setText("Monitor de temperatura y humedad")
  18.                     .setPosition(10,10)
  19.                     .setColorValue(0xffffff00)
  20.                     .setFont(createFont("Georgia",20))
  21.                     ;
  22.   cp5.addTextfield("Temperatura")
  23.     .setPosition(20, 60)
  24.     .setSize(200, 40)
  25.     .setFocus(true)
  26.     .setColor(color(255, 0, 0))
  27.     ;
  28.   cp5.addSlider("Temp")
  29.     .setPosition(350, 60)
  30.     .setSize(30, 200)
  31.     .setRange(0, 200)
  32.     .setValue(128)
  33.  
  34.     ;
  35.   cp5.getController("Temp").getValueLabel().align(ControlP5.CENTER, ControlP5.TOP_OUTSIDE).setPaddingY(0);
  36.   cp5.getController("Temp").getCaptionLabel().align(ControlP5.CENTER, ControlP5.BOTTOM_OUTSIDE).setPaddingY(0);
  37.   //cp5.getController("Temp").setColorCaptionLabel(0);
  38.   cp5.addTextfield("Humedad")
  39.     .setPosition(20, 120)
  40.     .setSize(200, 40)
  41.     .setFocus(true)
  42.     .setColor(color(255, 0, 0))
  43.     ;
  44.   cp5.addTextfield("Humedad_Tierra")
  45.     .setPosition(20, 180)
  46.     .setSize(200, 40)
  47.     .setFocus(true)
  48.     .setColor(color(255, 0, 0))
  49.     ;
  50.   cp5.addTextlabel("label")
  51.     .setPosition(240, 180)
  52.     .setText("Avisar humedad en tierra")
  53.     .setColor(color(255, 0, 0))
  54.     ;
  55.   cp5.addTextfield("avisar_humedad")
  56.     .setPosition(240, 200)
  57.     .setSize(80, 40)
  58.     .setFocus(true)
  59.     .setColor(color(255, 0, 0))
  60.     ;
  61. }
  62. void draw() {
  63.   background(0);
  64.   if (serie.available()>0) {
  65.     char id_dato = serie.readChar();
  66.     String dato = readstring();
  67.     if (id_dato == 'T') {
  68.       cp5.get(Textfield.class, "Temperatura").setText(dato+"ΒΊC");
  69.       if (dato.length()<7) {
  70.         cp5.get(Slider.class, "Temp").setValue(parseInt(dato.trim()));  
  71.         //println(dato+"  "+(dato.length()));
  72.       }
  73.     } if (id_dato == 'H') {
  74.       cp5.get(Textfield.class, "Humedad").setText(dato+"%");
  75.     } if (id_dato == 'E') {
  76.       //cp5.get(Textfield.class,"input").setText(dato);
  77.     } if (id_dato == 'L') {
  78.       cp5.get(Textfield.class, "Humedad_Tierra").setText(dato);
  79.       if(dato.trim().length()<5&& parseInt(dato.trim())>=hum_alerta){
  80.       println("Esta Seca");
  81.       }
  82.     }
  83.   }
  84. }
  85. String readstring() {
  86.   char dato = serie.readChar();
  87.   String d = "";
  88.   long s = millis();  
  89.   while (dato != '\n' && ((millis()-s)<=10)) {
  90.     d+=dato;
  91.     dato = serie.readChar();
  92.     //delay(5);
  93.   }
  94.   return d;
  95. }
  96.  
  97. public void avisar_humedad(String v) {
  98.   hum_alerta = parseInt(v);
  99.   println(v);
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement