Advertisement
Guest User

Untitled

a guest
Mar 11th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import processing.serial.*;
  2.  
  3. Serial port;
  4.  
  5. color fillVal = color(0);
  6. color backVal = color(255);
  7.  
  8. char letter = 'n';
  9.  
  10. //motor full forward = 100
  11. //motor neutral = 50
  12. //motor reverse = 0
  13.  
  14. void setup()
  15. {
  16. size(500, 500);
  17. println(Serial.list());
  18. port = new Serial(this, Serial.list()[0], 19200);
  19. }
  20.  
  21. void draw()
  22. {
  23. background(backVal);
  24. fill(fillVal);
  25. rect(200, 200, 100, 100);
  26. if (keyPressed)
  27. {
  28. if (key == CODED)
  29. {
  30. switch(keyCode)
  31. {
  32. case UP:
  33. fillVal = 100;
  34. port.write("10000,10000,e");
  35. break;
  36. case DOWN:
  37. fillVal = 150;
  38. port.write("20000,20000,e");
  39. break;
  40. case LEFT:
  41. fillVal = 200;
  42. port.write("20000,10000,e");
  43. break;
  44. case RIGHT:
  45. fillVal = 250;
  46. port.write("10000,20000,e");
  47. break;
  48. }
  49. }
  50. switch(key)
  51. {
  52. case 'a':
  53. fillVal = 175;
  54. port.write("30000,30000,e");
  55. break;
  56. case 'd':
  57. fillVal = 225;
  58. port.write("40000,40000,e");
  59. break;
  60. }
  61. }
  62. else
  63. {
  64. fillVal = 0;
  65. port.write("5000,5000,e");
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement