I found this code online for controlling a max7219 8x8 matrix with an Arduino, and I am struggling to understand a few things about the code. Here is the whole code:
#include <LedControl.h>
int UD = 0;
int LR = 0; //Setting up controller//
LedControl lc=LedControl(8,10,9,1); //10 is to CLOCK, 9 = CS, 8=DIN//
void setup() {
Serial.begin(9600);
lc.shutdown(0,false); // turn off power saving, enables display
lc.setIntensity(0,1); // sets brightness (0~15 possible values)
lc.clearDisplay(0); // clear screen
}
void loop() {
UD = analogRead(A0);
LR = analogRead(A1);
char x_translate = map(LR, 1021, 0, 7, 0); //map(value, fromLow, fromHigh, toLow, toHigh)
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);
// not in shutdown mode
lc.clearDisplay(0);
lc.setLed(0,x_translate,y_translate,true);
delay(150); //adjust delay to get your joystick correct//
}
My first question has to do with what Serial.begin(9600)
means.
My biggest question is about translating the analog input of the joystick into lighting up the LED's on the matrix:
char x_translate = map(LR, 1021, 0, 7, 0); //map(value, fromLow, fromHigh, toLow, toHigh)
char y_translate = map(UD, 1021, 0, 0, 7);
Where does 1021 come from, and why is it the fromLow value, when it seems to be the maximum of whatever range it scales? And where do the 7's come from, and why are they in the positions they're in?
Lastly, what the hell is happening with all the Serial.print()
statements? What is Serial, and what is DEC?
As you can tell I'm pretty new to C++ so any help here would be appreciated, thanks.