Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * MTI Final Project
- * Remote Humidity an Temperature Sensor
- * Daniel Freitas - dfreitas@andrew.cmu.edu
- */
- import processing.serial.*;
- Serial myPort; // The serial port
- int inByte;
- int x = 30;
- int temp=0;
- int humid=0;
- PFont fontA;
- // Images
- PImage b; //image 1 - dry diaper
- PImage m; //image 2 - wet diaper
- void setup()
- {
- size(700, 600);
- background(135, 206, 250);
- println(Serial.list()); // List all the available serial ports
- myPort = new Serial(this, Serial.list()[4], 115200); // It only works at 115200
- // Load the font.
- fontA = loadFont("Ziggurat-HTF-Black-32.vlw");
- // Set the font and its size (in units of pixels)
- textFont(fontA, 32);
- // Only draw once
- // noLoop();
- }
- void draw() {
- while (myPort.available() > 0) { // reads serial
- int inBuffer = myPort.read();
- if (inBuffer >-1) { // if data is being transmited
- if (inBuffer >100){ //because serial writes ony works with integers from 0-255 I used an algorithm
- temp = inBuffer-100; // if it's > 100 means that it has detected humidity. The temperature value is the last 2 digits
- humid = 1;
- wet(temp);
- }else{ // if it's < 100 means that there's no humidity
- temp = inBuffer;
- humid = 0;
- dry(temp);
- }//inBuffer >100
- }//inBuffer != null
- println(humid);
- println(temp);
- } // while (myPort.available() > 0)
- }
- void drawRect(float x,float y, float z){
- fill(51,204,255);
- rect(x, y, 150,z);
- fill(51,255,102);
- rect(x+150, y, 150,z);
- fill(255,0,0);
- rect(x+250, y, 150,z);
- }
- void wet(int temp)
- {
- size(700, 600);
- background(135, 206, 250);
- m= loadImage("mum.png");
- fill(0); // Use fill() to change the value or color of the text
- text("Remote Baby Monitor " , x, 60);
- fill(51); // Use fill() to change the value or color of the text
- text("temperature " , x, 150);
- text(temp +" F", x+280, 150);
- fill(51);
- text("humidity " , x, 220);
- image(m,150,200);
- fill(51);
- text("change " , 200, 500);
- }
- void dry(int temp)
- {
- size(700, 600);
- background(135, 206, 250);
- b = loadImage("baby.png");
- fill(0); // Use fill() to change the value or color of the text
- text("Remote Baby Monitor " , x, 60);
- fill(51); // Use fill() to change the value or color of the text
- text("temperature " , x, 150);
- text(temp +" F", x+280, 150);
- fill(51);
- text("humidity " , x, 220);
- image(b,100,200);
- fill(51);
- text("OK" , 180, 470);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement