Advertisement
Guest User

MTI - Final-Project Remote Temperature e Humidity Sensor - Processing

a guest
Dec 11th, 2010
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. /**
  2. * MTI Final Project
  3. * Remote Humidity an Temperature Sensor
  4. * Daniel Freitas - dfreitas@andrew.cmu.edu
  5. */
  6.  
  7.  
  8. import processing.serial.*;
  9.  
  10. Serial myPort; // The serial port
  11. int inByte;
  12. int x = 30;
  13.  
  14. int temp=0;
  15. int humid=0;
  16.  
  17. PFont fontA;
  18.  
  19.  
  20. // Images
  21.  
  22. PImage b; //image 1 - dry diaper
  23. PImage m; //image 2 - wet diaper
  24.  
  25.  
  26.  
  27.  
  28. void setup()
  29. {
  30.  
  31. size(700, 600);
  32. background(135, 206, 250);
  33.  
  34.  
  35.  
  36. println(Serial.list()); // List all the available serial ports
  37. myPort = new Serial(this, Serial.list()[4], 115200); // It only works at 115200
  38.  
  39.  
  40.  
  41. // Load the font.
  42. fontA = loadFont("Ziggurat-HTF-Black-32.vlw");
  43. // Set the font and its size (in units of pixels)
  44. textFont(fontA, 32);
  45.  
  46. // Only draw once
  47. // noLoop();
  48.  
  49.  
  50.  
  51. }
  52.  
  53.  
  54. void draw() {
  55.  
  56.  
  57.  
  58.  
  59. while (myPort.available() > 0) { // reads serial
  60.  
  61.  
  62. int inBuffer = myPort.read();
  63.  
  64. if (inBuffer >-1) { // if data is being transmited
  65.  
  66. if (inBuffer >100){ //because serial writes ony works with integers from 0-255 I used an algorithm
  67.  
  68. temp = inBuffer-100; // if it's > 100 means that it has detected humidity. The temperature value is the last 2 digits
  69. humid = 1;
  70.  
  71.  
  72. wet(temp);
  73.  
  74. }else{ // if it's < 100 means that there's no humidity
  75.  
  76. temp = inBuffer;
  77. humid = 0;
  78.  
  79. dry(temp);
  80.  
  81.  
  82. }//inBuffer >100
  83.  
  84.  
  85. }//inBuffer != null
  86.  
  87.  
  88. println(humid);
  89. println(temp);
  90.  
  91.  
  92.  
  93. } // while (myPort.available() > 0)
  94.  
  95.  
  96. }
  97.  
  98.  
  99.  
  100.  
  101.  
  102. void drawRect(float x,float y, float z){
  103. fill(51,204,255);
  104. rect(x, y, 150,z);
  105.  
  106. fill(51,255,102);
  107. rect(x+150, y, 150,z);
  108.  
  109.  
  110. fill(255,0,0);
  111. rect(x+250, y, 150,z);
  112.  
  113.  
  114.  
  115. }
  116.  
  117.  
  118. void wet(int temp)
  119.  
  120. {
  121. size(700, 600);
  122. background(135, 206, 250);
  123.  
  124.  
  125. m= loadImage("mum.png");
  126.  
  127.  
  128.  
  129. fill(0); // Use fill() to change the value or color of the text
  130. text("Remote Baby Monitor " , x, 60);
  131.  
  132.  
  133. fill(51); // Use fill() to change the value or color of the text
  134. text("temperature " , x, 150);
  135.  
  136. text(temp +" F", x+280, 150);
  137.  
  138.  
  139.  
  140. fill(51);
  141. text("humidity " , x, 220);
  142.  
  143. image(m,150,200);
  144.  
  145. fill(51);
  146. text("change " , 200, 500);
  147.  
  148. }
  149.  
  150.  
  151. void dry(int temp)
  152.  
  153. {
  154. size(700, 600);
  155. background(135, 206, 250);
  156.  
  157. b = loadImage("baby.png");
  158.  
  159.  
  160.  
  161. fill(0); // Use fill() to change the value or color of the text
  162. text("Remote Baby Monitor " , x, 60);
  163.  
  164.  
  165. fill(51); // Use fill() to change the value or color of the text
  166. text("temperature " , x, 150);
  167.  
  168. text(temp +" F", x+280, 150);
  169.  
  170.  
  171.  
  172. fill(51);
  173. text("humidity " , x, 220);
  174.  
  175. image(b,100,200);
  176.  
  177. fill(51);
  178. text("OK" , 180, 470);
  179.  
  180.  
  181.  
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement