Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "LedControlMS.h"
- LedControl lc=LedControl(11,9,10,1);
- int LedControl::getDeviceCount();
- int i;
- int j=5;
- int x;
- int y;
- const int inX = A0; // analog input for x-axis
- const int inY = A1; // analog input for y-axis
- const int inPressed = 3; // input for detecting whether the joystick/button is pressed
- int xValue = 0; // variable to store x value
- int yValue = 0; // variable to store y value
- int notPressed = 0; // variable to store the button's state => 1 if not pressed
- void setup() {
- lc.shutdown(0,false);
- pinMode(inX, INPUT); // setup x input
- pinMode(inY, INPUT); // setup y input
- pinMode(inPressed, INPUT_PULLUP);
- }
- void loop() {
- ram();
- kretanje();
- restart();
- }
- void ram()
- {
- lc.setIntensity(0,5);
- for(int i=0;i<8;i++)
- {lc.setLed(0,i,0,true);
- lc.setLed(0,i,7,true);
- }
- for(int i=0;i<8;i++)
- {lc.setLed(0,0,i,true);
- lc.setLed(0,7,i,true);
- }
- }
- void kretanje()
- {
- x=3;
- y=4;
- lc.setLed(0,x,y,true);
- while((x>0 && x<7) && (y>0 && y<7))
- {
- xValue = analogRead(inX); // reading x value [range 0 -> 1023]
- yValue = analogRead(inY);
- while(yValue>600)
- { xValue = analogRead(inX); // reading x value [range 0 -> 1023]
- yValue = analogRead(inY);
- y++;
- if(y==7) break;
- lc.setLed(0,x,y-1,false);
- lc.setLed(0,x,y,true);
- delay(300);
- }
- while(yValue<400)
- { xValue = analogRead(inX); // reading x value [range 0 -> 1023]
- yValue = analogRead(inY);
- y--;
- if(y==0) break;
- lc.setLed(0,x,y+1,false);
- lc.setLed(0,x,y,true);
- delay(300);
- }
- while(xValue>600)
- { xValue = analogRead(inX); // reading x value [range 0 -> 1023]
- yValue = analogRead(inY);
- x--;
- if(x==0) break;
- lc.setLed(0,x+1,y,false);
- lc.setLed(0,x,y,true);
- delay(300);
- }
- while(xValue<400)
- { xValue = analogRead(inX); // reading x value [range 0 -> 1023]
- yValue = analogRead(inY);
- x++;
- if(x==7) break;
- lc.setLed(0,x-1,y,false);
- lc.setLed(0,x,y,true);
- delay(300);
- }
- }
- lc.shutdown(0,true);
- }
- void restart()
- {
- notPressed = digitalRead(inPressed);
- if(notPressed==0) kretanje();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement