augusto0112

lab8.1

Oct 25th, 2016
742
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.99 KB | None | 0 0
  1. /*
  2. ********** Processing **********
  3.  * Laboratorio 08: Temperatura y humedad con DHT11 y Luz con (LdR, CdS) con una interfaz gráfica
  4.  * Autor: Cristian Augusto Restrepo
  5.  * Fecha: 25/10/2016
  6.  * Descripcion:
  7.  *   Mostrar en una interfaz de Processing la temperatura y humedad (DTH11),
  8.  *   y el nivel de iluminación capturado con una fotoresistencia (LdR, CdS) medidas a través de un Arduino.
  9. */
  10. import processing.serial.*;
  11. Serial myPort;
  12. String sensorReading="0.0.0.0.0";
  13. PImage fondo;
  14.  
  15. void setup() {
  16.   size(600, 600);
  17.   fondo = loadImage("fondo.jpg");
  18.   String portName = Serial.list()[0];
  19.   myPort = new Serial(this, portName, 9200);
  20.   myPort.bufferUntil('\n');
  21. }
  22.  
  23. void draw() {
  24.   background(255);
  25.   image(fondo, 0, 0);
  26.  
  27.   int sensors[] = int(split(sensorReading, '.'));
  28.   drawTemp(sensors[0]);
  29.   drawHumedad(sensors[2]);
  30.   drawIluminacion(sensors[4]);
  31.   fill(0);
  32.   textSize(14);
  33.   text("Sistema de medición - Cristian Restrepo", 10, 500);
  34.   println("Temperatura: "+sensors[0]+" - Humedad: "+sensors[2]+" - Iluminación: "+sensors[4]);
  35. }
  36.  
  37. void drawTemp(int temp){
  38.   // la temperatura va de -40º a 50º centigrados
  39.   int altura = (int) map(temp, -40, 50, 0, -295);
  40.   stroke(255, 0, 0);
  41.   fill(255, 0, 0);
  42.   rect(83, 400, 8, altura);
  43. }
  44.  
  45. void drawHumedad(int hum){
  46.   int cx = 323, cy = 146, radio = 100;
  47.   // la humedad va de 0% a 100%
  48.   float angulo = map(hum, 0, 100, -240, 60) * (PI/180);
  49.   stroke(250,48,48);
  50.   strokeWeight(4);
  51.   line(cx, cy, cx + cos(angulo) * radio, cy + sin(angulo) * radio);
  52. }
  53.  
  54. void drawIluminacion(int ilum){
  55.   int cx = 323, cy = 475, radio = 130;
  56.   // la potencia de la luz va de 0 a 100 en una escala de 10x
  57.   float angulo = map(ilum/10, 0, 200, -140, 60) * (PI/180);
  58.   stroke(250,48,48);
  59.   strokeWeight(4);
  60.   line(cx, cy, cx + cos(angulo) * radio, cy + sin(angulo) * radio);
  61. }
  62.  
  63. void serialEvent (Serial myPort){
  64.   sensorReading = myPort.readStringUntil('\n');
  65.   if(sensorReading != null){
  66.     sensorReading=trim(sensorReading);
  67.   }
  68. }
Add Comment
Please, Sign In to add comment