Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "LedControl.h"
- int potX = A5;
- int potY = A8;
- int ldr = A9;
- const int buttonPin = 1;
- int joyX = 0;
- int joyY = 0;
- int ldr_val = 0;
- LedControl lc=LedControl(10,11,12,1);
- void SetAllOn()
- {
- for(int row=0;row<8;row++)
- {
- for(int col=0;col<8;col++)
- {
- lc.setLed(0,row,col,true);
- }
- }
- }
- void SetAllOff()
- {
- for(int row=0;row<8;row++)
- {
- for(int col=0;col<8;col++)
- {
- lc.setLed(0,row,col,false);
- }
- }
- }
- void SetSingleOn(int xpos, int ypos)
- {
- for(int row=0;row<8;row++)
- {
- for(int col=0;col<8;col++)
- {
- if(row == xpos && col == ypos)
- lc.setLed(0,row,col,true);
- else
- lc.setLed(0,row,col,false);
- }
- }
- }
- void setup()
- {
- pinMode(buttonPin, INPUT);
- lc.shutdown(0,false);
- lc.setIntensity(0,8);
- lc.clearDisplay(0);
- SetAllOff();
- }
- void RandomFill()
- {
- lc.setLed(0, random(0,8), random(0,8), random(0,2));
- delay(3);
- }
- int AvgRead()
- {
- unsigned int sum = 0;
- for(int i = 0; i < 50; i++)
- {
- sum += analogRead(ldr);
- }
- return sum / 50;
- }
- void loop()
- {
- int xpos = 0;
- int ypos = 0;
- joyX = analogRead(potX);
- joyY = analogRead(potY);
- ldr_val = AvgRead();
- lc.setIntensity(0, map(ldr_val, 0, 1023, 0, 15));
- xpos = map(joyX, 0, 1023, 7, 0);
- ypos = map(joyY, 0, 1023, 7, 0);
- SetSingleOn(xpos, ypos);
- while(digitalRead(buttonPin) == 0)
- {
- RandomFill();
- ldr_val = AvgRead();
- lc.setIntensity(0, map(ldr_val, 32, 1023, 0, 15));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement