Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ********** Processing **********
- * Laboratorio 08: Temperatura y humedad con DHT11 y Luz con (LdR, CdS) con una interfaz gráfica
- * Autor: Cristian Augusto Restrepo
- * Fecha: 25/10/2016
- * Descripcion:
- * Mostrar en una interfaz de Processing la temperatura y humedad (DTH11),
- * y el nivel de iluminación capturado con una fotoresistencia (LdR, CdS) medidas a través de un Arduino.
- */
- import processing.serial.*;
- Serial myPort;
- String sensorReading="0.0.0.0.0";
- PImage fondo;
- void setup() {
- size(600, 600);
- fondo = loadImage("fondo.jpg");
- String portName = Serial.list()[0];
- myPort = new Serial(this, portName, 9200);
- myPort.bufferUntil('\n');
- }
- void draw() {
- background(255);
- image(fondo, 0, 0);
- int sensors[] = int(split(sensorReading, '.'));
- drawTemp(sensors[0]);
- drawHumedad(sensors[2]);
- drawIluminacion(sensors[4]);
- fill(0);
- textSize(14);
- text("Sistema de medición - Cristian Restrepo", 10, 500);
- println("Temperatura: "+sensors[0]+" - Humedad: "+sensors[2]+" - Iluminación: "+sensors[4]);
- }
- void drawTemp(int temp){
- // la temperatura va de -40º a 50º centigrados
- int altura = (int) map(temp, -40, 50, 0, -295);
- stroke(255, 0, 0);
- fill(255, 0, 0);
- rect(83, 400, 8, altura);
- }
- void drawHumedad(int hum){
- int cx = 323, cy = 146, radio = 100;
- // la humedad va de 0% a 100%
- float angulo = map(hum, 0, 100, -240, 60) * (PI/180);
- stroke(250,48,48);
- strokeWeight(4);
- line(cx, cy, cx + cos(angulo) * radio, cy + sin(angulo) * radio);
- }
- void drawIluminacion(int ilum){
- int cx = 323, cy = 475, radio = 130;
- // la potencia de la luz va de 0 a 100 en una escala de 10x
- float angulo = map(ilum/10, 0, 200, -140, 60) * (PI/180);
- stroke(250,48,48);
- strokeWeight(4);
- line(cx, cy, cx + cos(angulo) * radio, cy + sin(angulo) * radio);
- }
- void serialEvent (Serial myPort){
- sensorReading = myPort.readStringUntil('\n');
- if(sensorReading != null){
- sensorReading=trim(sensorReading);
- }
- }
Add Comment
Please, Sign In to add comment