int UD = 0;
int LR = 0;
int buttonPin1 = 2;
int buttonPin2 = 3;
#include "LedControl.h"
LedControl lc=LedControl(11,13,10,1); // initialize with DIN on pin 11, CLK on pin 13, CS on pin 10, and 1 matrix connected
void setup() {
Serial.begin(9600);
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
}
void loop() {
UD = analogRead(A0);
LR = analogRead(A1);
char x_translate = map(LR, 1021, 0, 7, 0);
char y_translate = map(UD, 1021, 0, 0, 7);
Serial.print("UD = ");
Serial.print(UD, DEC);
Serial.print(", LR = ");
Serial.print(LR, DEC);
Serial.print(", x = ");
Serial.print(x_translate, DEC);
Serial.print(", y = ");
Serial.println(y_translate, DEC);
lc.clearDisplay(0);
lc.setLed(0,x_translate,y_translate,true);
if (digitalRead(buttonPin1) == LOW) {
lc.setIntensity(0,0); // set brightness to 0
delay(500);
lc.setIntensity(0,8); // set brightness back to 8
delay(500);
}
if (digitalRead(buttonPin2) == LOW) {
lc.clearDisplay(0); // clear display
delay(200);
lc.setLed(0,0,0,true); // set LED at (0,0) to on
delay(200);
lc.setLed(0,0,0,false); // set LED at (0,0) to off
delay(200);
lc.setLed(0,7,7,true); // set LED at (7,7) to on
delay(200);
lc.setLed(0,7,7,false); // set LED at (7,7) to off
delay(200);
lc.clearDisplay(0); // clear display
}
delay(50);
}