Hi
I have a 8x8 led matrix(max7219) where the individual leds are selected by two potentiometers and two switches.Pot 1 selects up down.pot 2 selects left right and the two switches select or cancel the led at the current position.This is to display the on/off status of some octal switches eventually.
I'm struggling to find some information how to adapt this sketch so I can use more 8x8's to create a 16x16 and 24x24 display.
I have 4 8x8's laid out like............
1....2....
3....4....
obviously at the moment I get the same thing on all them
I'd be grateful if anyone could advise me or point me in the right direction as to what I need to change in the sketch
/* This sketch detects analog signals from the potentiometers
and sends it to the serial monitor */
//initialize variable for x and y values on the potentiometers and the pushbuttons at digital pin 4 and 7
int UD;
int LR ;
int button_a = 4;
int button_b = 7;
bool stored_state [8][8];
int last_x, last_y;
#include "LedControl.h" // importing the library
// DIN to 10, CLK to 12, CS to 11
LedControl lc = LedControl(10, 12, 11, 0);
void setup() {
Serial.begin(9600);
lc.shutdown(0, false); // turn off power saving, enables display
lc.setIntensity(0, 8); // sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
pinMode(button_a, INPUT); // button is input
digitalWrite(button_a, HIGH); // initalize button as ON
pinMode(button_b, INPUT); // button is input
digitalWrite(button_b, HIGH); // initalize button as ON
}
void loop() {
UD = analogRead(A1); // read analog value at pin A1 and stores as UD
LR = analogRead(A0); // read analog value at pin A0 and stores as LR
int stateA = digitalRead(button_a); //determines the state of button_a (HIGH or LOW)
int stateB = digitalRead(button_b); //determines the state of button_b (HIGH or LOW)
// scales down the value from 0-1023 to 0-7
char x_translate = map(LR, 0, 1023, 7, 0);
char y_translate = map(UD, 0, 1023, 0, 7);
if ( (last_x != x_translate) || (last_y != y_translate) )
{
// the position has moved so we need to restore previous state
lc.setLed(0, last_x, last_y, stored_state [last_x][last_y] );
}
last_x = x_translate;
last_y = y_translate;
Serial.print ("Button_a=");
Serial.print(stateA, DEC);
Serial.print ("Button_b=");
Serial.print(stateB, DEC);
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);
// clears display whenever a new value is updated
/// --> dont do this! lc.clearDisplay(0);
// just set led in new joystick position
lc.setLed(0, x_translate, y_translate, true);
// if button_a is pressed, store it
if (stateA == 1) {
stored_state [last_x][last_y] = true;
}
// if button_b is pressed, delete it
if (stateB == 1) {
stored_state [last_x][last_y] = false;
}
delay(150); //Mess with delay to tweak accuracy
}