Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. /**
  2. * Simple Read
  3. *
  4. * Read data from the serial port and change the color of a rectangle
  5. * when a switch connected to a Wiring or Arduino board is pressed and released.
  6. * This example works with the Wiring / Arduino program that follows below.
  7. */
  8.  
  9.  
  10. import processing.serial.*;
  11.  
  12. Serial myPort; // Create object from Serial class
  13. int val; // Data received from the serial port
  14.  
  15. void setup()
  16. {
  17. size(200, 200);
  18. // I know that the first port in the serial list on my mac
  19. // is always my FTDI adaptor, so I open Serial.list()[0].
  20. // On Windows machines, this generally opens COM1.
  21. // Open whatever port is the one you're using.
  22. String portName = Serial.list()[5];
  23. printArray(Serial.list());
  24. myPort = new Serial(this, portName, 19200);
  25. }
  26.  
  27. void draw()
  28. {
  29. while (myPort.available() > 0) {
  30. String inBuffer = myPort.readString();
  31. if (inBuffer != null) {
  32. String[] splittedList = split(inBuffer, ",");
  33. if (splittedList.length == 6) {
  34. float temperatureVolt = (unhex(splittedList[2]) / 10.0) * (68.0 + 39.0) / 39.0;
  35. float humidityVolt = (unhex(splittedList[3]) / 10.0) * (68.0 + 39.0) / 39.0;
  36. float voltage = int(trim(splittedList[5]))/1000.0;
  37. temperatureVolt /= 1000.0;
  38. humidityVolt /= 1000.0;
  39. print("VCC: "); print(voltage);
  40. print("\tTemp V: "); print(temperatureVolt); print("\tHumidity V: "); println(humidityVolt);
  41. float temperature = -45-(17.5/0.8)+(175/0.8)*(temperatureVolt/voltage);
  42. float humidity = -(10/0.8)+(100/0.8)*(humidityVolt/voltage);
  43. print(temperature);print("°C\t");
  44. print(humidity);println("%");
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement