Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. IntList M,R,G,H;
  2. import processing.serial.*;
  3. int Width=800;
  4. Serial myPort;
  5. int Lenght=400;
  6.  
  7. void setup(){
  8. String portName = Serial.list()[0];
  9. myPort = new Serial(this, portName, 9600);
  10. size(800, 400);
  11. M = new IntList();
  12. R = new IntList();
  13. G = new IntList();
  14. H = new IntList();
  15. for (int i=0; i<200; i++) {
  16. M.append(1);
  17. R.append(1);
  18. G.append(1);
  19. H.append(1);
  20. }
  21. fill(255);
  22. rectMode(CORNERS);
  23. }
  24.  
  25. void print_please(){
  26. background(0);
  27. graph();
  28. }
  29.  
  30. void draw(){
  31. if (myPort.available()>=4){
  32. int x = myPort.read();
  33. int y = myPort.read();
  34. int z = myPort.read();
  35. int s = myPort.read();
  36. M.remove(0);
  37. //M.append(M.get(M.size()-1)+(int)random(-3,3));
  38. M.append(x);
  39. R.remove(0);
  40. R.append(y);
  41. G.remove(0);
  42. G.append(z);
  43. H.remove(0);
  44. H.append(s);
  45. print_please();}
  46. }
  47.  
  48.  
  49. void graph(){
  50. for (int i=0; i<200; i++){
  51. fill(255,0,0);
  52. rect((i*3)+20, 400-M.get(i), ((i+1)*3)+20, 400-M.get(i)+5);
  53. fill(0,255,0);
  54. rect((i*3)+20, 400-R.get(i), ((i+1)*3)+20, 400-R.get(i)+5);
  55. fill(0,0,255);
  56. rect((i*3)+20, 400-G.get(i), ((i+1)*3)+20, 400-G.get(i)+5);
  57. fill(125,125,125);
  58. rect((i*3)+20, 400-H.get(i), ((i+1)*3)+20, 400-H.get(i)+5);
  59. }
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. void setup() {
  73. pinMode(A0, INPUT);
  74. pinMode(A1, INPUT);
  75. pinMode(A2, INPUT);
  76. pinMode(A3, INPUT);
  77. Serial.begin(9600);
  78. }
  79.  
  80. void loop() {
  81. int x,y,z,s;
  82. x = analogRead(A0);
  83. y = analogRead(A1);
  84. z = analogRead(A2);
  85. s = analogRead(A3);
  86. Serial.write(x/4);
  87. Serial.write(y/4);
  88. Serial.write(z/4);
  89. Serial.write(s/4);
  90. delay(50);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement