Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import processing.serial.*;
  2. PImage img; // Declare variable "a" of type PImage
  3.  
  4. int x=350;
  5. int y=350;//el punto centro de la pantalla
  6. int grados=0;//inicio de grados en el que se encuentra el rectangulo
  7. Serial port;//puerto por el que vamos a recibir los datos
  8. int valor = 0;
  9. int[] wormx = new int[10];
  10. int[] wormy = new int[10];
  11. void setup()
  12. {
  13. size(640, 360);
  14. // The image file must be in the data folder of the current sketch
  15. // to load successfully
  16. img = loadImage("nav.png"); // Load the image into the program
  17. port = new Serial(this, Serial.list()[0], 9600);
  18. size(1000,700);//tamaƱo de la ventana
  19. frameRate(60);// especifica el numero de fotogramas que muestra por segundo
  20. smooth();//suavizar
  21. fill(255,120,0);//color del cuadro
  22.  
  23. }
  24.  
  25. void draw ()
  26. {
  27. while (port.available() > 0)
  28. {
  29. String cadena ="00"+port.readString(); //Lectura de datos desde arduino
  30. valor = int(cadena.substring(2,cadena.length()));
  31. println(cadena + ":" + valor);
  32. }
  33.  
  34. background (0,0,0);//color de fondo
  35. pushMatrix();//entrada a la pila de matriz
  36. translate(x, y);//trasladamos el rectangulo en pantalla con respecto a su estado
  37. rotate(radians(grados));//rotamos el rectangulo el numero de grados indicado
  38. // Displays the image at its actual size at point (0,0)
  39. image(img, 0, 0);
  40. // Displays the image at point (0, height/2) at half of its size
  41. image(img, 0, height, img.width, img.height);
  42. popMatrix();//restaura la pila de matriz
  43.  
  44.  
  45.  
  46. //Condiciones que dependen del los valores recibidos desde arduino (movimientos de joystick)
  47. if (valor == 1)
  48. {
  49. valor=0;
  50. y-=10;
  51. if (y<10) y=690;
  52. }
  53.  
  54. if (valor == 2)
  55. {
  56. valor=0;
  57. y+=10;
  58. if (y>670) y=10;
  59. }
  60.  
  61. if (valor == 3)
  62. {
  63. valor=0;
  64. x+=10;
  65. if (x>670) x=10;
  66. }
  67.  
  68. if (valor == 4)
  69. {
  70. valor=0;
  71. x-=10;
  72. if (x<10) x=690;
  73. }
  74.  
  75. if (valor == 13)
  76. {
  77. valor=0;
  78. y-=10;
  79. if (y>670) y=10;
  80. x+=10;
  81. if (x<10) x=690;
  82. }
  83.  
  84.  
  85. if (valor == 14)
  86. {
  87. valor=0;
  88. y-=10;
  89. if (y>670) y=690;
  90. x-=10;
  91. if (x<10) x=10;
  92. }
  93.  
  94. if (valor == 24)
  95. {
  96. valor=0;
  97. y+=10;
  98. if (y>670) y=690;
  99. x-=10;
  100. if (x<10) x=690;
  101. }
  102.  
  103. if (valor == 23)
  104. {
  105. valor=0;
  106. y+=10;
  107. if (y>670) y=690;
  108. x+=10;
  109. if (x<10) x=690;
  110. }
  111.  
  112.  
  113. }