Guest User

Untitled

a guest
Jun 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. //Libreria para comunicarse con arduino
  2. import processing.serial.*;
  3. // Declarando el nombre de nuestro puerto serial
  4. Serial myPort;
  5. //Variable para leer el valor recibido de arduino
  6. String val;
  7. void setup() {
  8. size(500, 500);
  9. background(0);
  10. // Declarando el puerto Serial y la velocidad de transferencia
  11. myPort= new Serial(this, "COM3", 9600);
  12. myPort.bufferUntil('\n');
  13. }
  14. //Declarando nuesvos arreglos de objetos
  15. Agua[] atomos_agua=new Agua[1];
  16. CO2[] atomos_CO2=new CO2[1];
  17. Oxigeno[] atomos_oxigeno=new Oxigeno[1];
  18.  
  19. void draw() {
  20. //Inicializando los objetos
  21. atomos_agua[0]=new Agua();
  22. atomos_CO2[0]=new CO2();
  23. atomos_oxigeno[0]=new Oxigeno();
  24. // Cuando se esten recibiendo datos
  25. if (myPort.available()>0) {
  26. val = myPort.readStringUntil('\n');
  27. // Lee el dato recibido
  28. if (val!=null) {
  29. // Cuando el dato es diferente de nulo limpia la pantalla
  30. println(val);
  31. background(0);
  32. }
  33. } else {
  34. // cuando no se reciben datos
  35. if (keyPressed) {
  36. //si se presiona la letra a envia un dato y muestra en pantalla el atomo de agua
  37. if (key == 'a') {
  38. background(0);
  39. myPort.write("a");
  40. atomos_agua[0].display();
  41. }
  42. //si se presiona la letra d envia un dato y muestra en pantalla el atomo de CO2
  43. else if (key == 'd') {
  44. background(0);
  45. myPort.write("d");
  46. atomos_CO2[0].display();
  47. }//si se presiona la letra o envia un dato y muestra en pantalla el atomo de oxigeno
  48. else if (key == 'o') {
  49. background(0);
  50. myPort.write("o");
  51. atomos_oxigeno[0].display();
  52. }
  53. }
  54. }
  55. }
  56.  
  57.  
  58. // se declara la clase
  59. class Agua
  60. {
  61. int x;
  62. int y;
  63. float tam;
  64. // constructor de la clase donde se define la posicion y tamaño
  65. Agua()
  66. {
  67. x=width/2;
  68. y=(height/2);
  69. tam=50;
  70. }
  71. // metodo que se utiliza para dibujar el atomo
  72. void display() {
  73. // Coloca los textos descriptivos
  74. fill(255);
  75. textSize(15);
  76. text("Oxigeno",width/2,350);
  77. text("Hidrogeno",150,100);
  78. text("Hidrogeno",290,100);
  79. stroke(255);
  80. // Dibuja la lineas que uniran a los elipses
  81. line(x,y,x-150,y-150);
  82. line(x,y,x+150,y-150);
  83. fill(0, 255, 0);
  84. ellipse(x, y, tam+75, tam+75);
  85. fill(0, 0, 255);
  86. ellipse(x+150, y-150, tam, tam);
  87. ellipse(x-150, y-150, tam, tam);
  88. }
  89. }
  90.  
  91. // se declara la clase
  92. class CO2
  93. {
  94. int x;
  95. int y;
  96. float tam;
  97. // constructor de la clase donde se define la posicion y tamaño
  98. CO2()
  99. {
  100. x=width/2;
  101. y=(height/2);
  102. tam=50;
  103. }
  104. // metodo que se utiliza para dibujar el atomo
  105. void display() {
  106. // Coloca los textos descriptivos
  107. fill(255);
  108. textSize(15);
  109. text("Oxigeno",150,400);
  110. text("Oxigeno",150,100);
  111. text("Carbono",350,height/2);
  112. stroke(255);
  113. // Dibuja la lineas que uniran a los elipses
  114. line(x,y,x,y-150);
  115. line(x,y,x,y+150);
  116. fill(255, 0, 0);
  117. ellipse(x, y, tam+50, tam+50);
  118. fill(0,255, 0);
  119. ellipse(x, y+150, tam, tam);
  120. ellipse(x, y-150, tam, tam);
  121. }
  122. }
  123.  
  124. // se declara la clase
  125. class Oxigeno
  126. {
  127. int x;
  128. int y;
  129. float tam;
  130. // constructor de la clase donde se define la posicion y tamaño
  131. Oxigeno()
  132. {
  133. x=width/2;
  134. y=(height/2);
  135. tam=150;
  136. }
  137. // metodo que se utiliza para dibujar el atomo
  138. void display() {
  139. // Coloca los textos descriptivos
  140. fill(255);
  141. text("Oxigeno",width/2,100);
  142. fill(0, 150, 255);
  143. ellipse(x, y, tam, tam);
  144.  
  145. }
  146. }
Add Comment
Please, Sign In to add comment