Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include "LedControlMS.h"
  2. LedControl lc=LedControl(11,9,10,1);
  3. int LedControl::getDeviceCount();
  4. int i;
  5. int j=5;
  6. int x;
  7. int y;
  8. const int inX = A0; // analog input for x-axis
  9. const int inY = A1; // analog input for y-axis
  10. const int inPressed = 3; // input for detecting whether the joystick/button is pressed
  11.  
  12. int xValue = 0; // variable to store x value
  13. int yValue = 0; // variable to store y value
  14. int notPressed = 0; // variable to store the button's state => 1 if not pressed
  15. void setup() {
  16.  
  17. lc.shutdown(0,false);
  18. pinMode(inX, INPUT); // setup x input
  19. pinMode(inY, INPUT); // setup y input
  20. pinMode(inPressed, INPUT_PULLUP);
  21. }
  22.  
  23. void loop() {
  24.  
  25. ram();
  26. kretanje();
  27. restart();
  28.  
  29. }
  30. void ram()
  31. {
  32. lc.setIntensity(0,5);
  33. for(int i=0;i<8;i++)
  34. {lc.setLed(0,i,0,true);
  35. lc.setLed(0,i,7,true);
  36.  
  37. }
  38. for(int i=0;i<8;i++)
  39. {lc.setLed(0,0,i,true);
  40. lc.setLed(0,7,i,true);
  41. }
  42. }
  43. void kretanje()
  44. {
  45.  
  46. x=3;
  47. y=4;
  48. lc.setLed(0,x,y,true);
  49.  
  50. while((x>0 && x<7) && (y>0 && y<7))
  51. {
  52. xValue = analogRead(inX); // reading x value [range 0 -> 1023]
  53. yValue = analogRead(inY);
  54. while(yValue>600)
  55. { xValue = analogRead(inX); // reading x value [range 0 -> 1023]
  56. yValue = analogRead(inY);
  57. y++;
  58. if(y==7) break;
  59. lc.setLed(0,x,y-1,false);
  60. lc.setLed(0,x,y,true);
  61. delay(300);
  62.  
  63. }
  64. while(yValue<400)
  65. { xValue = analogRead(inX); // reading x value [range 0 -> 1023]
  66. yValue = analogRead(inY);
  67.  
  68. y--;
  69. if(y==0) break;
  70. lc.setLed(0,x,y+1,false);
  71. lc.setLed(0,x,y,true);
  72. delay(300);
  73. }
  74. while(xValue>600)
  75. { xValue = analogRead(inX); // reading x value [range 0 -> 1023]
  76. yValue = analogRead(inY);
  77.  
  78. x--;
  79. if(x==0) break;
  80. lc.setLed(0,x+1,y,false);
  81. lc.setLed(0,x,y,true);
  82. delay(300);
  83. }
  84. while(xValue<400)
  85. { xValue = analogRead(inX); // reading x value [range 0 -> 1023]
  86. yValue = analogRead(inY);
  87.  
  88. x++;
  89. if(x==7) break;
  90. lc.setLed(0,x-1,y,false);
  91. lc.setLed(0,x,y,true);
  92. delay(300);
  93. }
  94. }
  95. lc.shutdown(0,true);
  96. }
  97. void restart()
  98. {
  99. notPressed = digitalRead(inPressed);
  100. if(notPressed==0) kretanje();
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement