are you sure here ?
if you rotate joystick 180 degree then no value inversion is needed.
#include "LedControl.h" // need the library
const byte DIN = 11 ;
const byte CS = 10;
const byte CLK = 13;
LedControl lc(11, 13, 10, 4); //10 is to CLOCK, 9 = CS, 8=DIN//
const byte aX = A0;
const byte aY = A1;
const byte treshold = 15;
void setup() {
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
}
void loop() {
static byte cX = 24;
static byte cY = 0;
static int bX;
static int bY;
static char commando = '0';
do {
bX = analogRead(aX) - 512;
bY = analogRead(aY) - 512;
} while (abs(bX) < treshold && abs(bY) < treshold);
if (bX < -treshold)commando = 'L'; // if movement direction of joystick
if (bX > treshold)commando = 'R';
if (bY < -treshold)commando = 'D'; // not correspond to them of pixel
if (bX > treshold)commando = 'U'; // then here swap Letters
switch (commando) {
case 'L':
if (cX > 0)cX--;
break;
case 'R':
if (cX < 7)cX++;
break;
case 'U':
if (cY > 0)cY--;
break;
case 'D':
if (cY < 7)cY++;
break;
}
showPixel(cX, cY);
commando = '0';
do {
bX = analogRead(aX) - 512;
bY = analogRead(aY) - 512;
} while (abs(bX) > treshold || abs(bY) > treshold);
}
void showPixel(int x, int y) {
lc.clearDisplay(0);
lc.setLed(3 - x / 8, x % 8, y, true);
}

Yes, the Y values vary a bit... other than that. it's nearly the same.
I will try rewiring and see.
Thank you Kohala.
why rewiring? just place joystick with connector on the right
Yes, I will do that.
My bad, I used the wrong word.
I will not rewire, I am changing the joystick direction.
or adjust commando letters on marked place in sketch.
I am having some uploading error in the port.
Sketch uses 1790 bytes (5%) of program storage space. Maximum is 32256 bytes.
Global variables use 102 bytes (4%) of dynamic memory, leaving 1946 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "\.\COM4": Access is denied.
Failed uploading: uploading error: exit status 1
I will fix it and run.
Hi Kohala,
Yes, finally with your help and support I managed to run the LED for one board.
Now into the next level of four board with 31by 31 LED.
I am working to running the single LED on any direction on 31 by 31 matrix.
Can you please give some inputs on how to avoid debouncing? After 0,0 the LED gets disappeared instead of not stopping at 0,0 as like previous.
By the way, please see the picture for the set-up.
how you declare 3 other panel? is it daisy chained?
Initial it was daisy chained.
However, I am unable to write the correct code to work for the daisy chained.
So now I am using separate pins for each panel.
I am repeating the same codes each panel pins.
Please see the code below.
#include <MD_MAX72xx.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 1
int DIN=11 ;
int CS=10;
int CLK=13;
int dt=100;
LedControl lc=LedControl(13,11,12,4); //10 is to CLOCK, 9 = CS, 8=DIN//
LedControl lc1=LedControl(10,8,9,4);
LedControl lc2=LedControl(7,5,6,4);
LedControl lc3=LedControl(4,2,3,4);
const byte aX=A0;
const byte aY=A1;
void setup(){
Serial.begin(9600);
int devices=lc.getDeviceCount();
for(int address=0;address<devices;address++) {
lc.shutdown(address,false);
lc1.shutdown(address,false);
lc2.shutdown(address,false);
lc3.shutdown(address,false);// turn off power saving, enables display
lc.setIntensity(address,8);
lc1.setIntensity(address,8);
lc2.setIntensity(address,8);
lc3.setIntensity(address,8);
/* and clear the display */
lc.clearDisplay(address);
lc1.clearDisplay(address);
lc2.clearDisplay(address);
lc3.clearDisplay(address);
}
}
void loop(){
int devices=lc.getDeviceCount();
/*int cX;
int cY;*/
static byte cX=0;
static byte cY=0;
int B=abs(cY/8);
Serial.print("B=");
Serial.println(B);
/*delay(dt);*/
/*int A=3-abs(cX/8);*/
int A=3-abs(cX/8);
Serial.print("A=");
Serial.println(A);
/*delay(dt);*/
int Bx=cX%8;
Serial.print("Bx=");
Serial.println(Bx);
/*delay(dt);*/
int By=cY%8;
Serial.print("By=");
Serial.println(By);
/*delay(dt);*/
if(B==0){
lc.setLed(A,By,Bx,true);
static int bX;
static int bY;
static char commando='0';
do {
bX=516-analogRead(aX);
Serial.print("bX position= ");
Serial.println(bX);
delay(dt);
bY=507-analogRead(aY);
Serial.print("bY position= ");
Serial.println(bY);
delay(dt);
}while ((bX)>30 && (bX)<20 && (bY)>30 && (bY)<20);
if(bX>350 && bX<360)commando='L';
switch (commando){
case 'L':
if(cX<32)cX--;
break;}
/*do {
bX=516-analogRead(aX);
bY=507-analogRead(aY);
}while (abs(bX)<5 && abs(bY)<5);*/
if(bX>10 && bX<16)commando='R';
switch (commando){
case 'R':
if(cX>-1)cX++;
break;
}
if(bX>178 && bX<184)commando='0';
switch (commando){
case 'O':
cX=4;
cY=4;
break;}
if(bY>0 && bY<8)commando='U';
switch (commando){
case 'U':
if(cX<32)cY--;
break;
}
if(bY>345 && bY<350)commando='D';
switch (commando){
case 'D':
if(cY<8)cY++;
break;
}
}
if(B==1){
lc.setLed(A,By,Bx,true);
static int bX;
static int bY;
static char commando='0';
do {
bX=516-analogRead(aX);
Serial.print("bX position= ");
Serial.println(bX);
delay(dt);
bY=507-analogRead(aY);
Serial.print("bY position= ");
Serial.println(bY);
delay(dt);
}while ((bX)>30 && (bX)<20 && (bY)>30 && (bY)<20);
if(bX>350 && bX<360)commando='L';
switch (commando){
case 'L':
if(cX<32)cX--;
break;}
if(bX>10 && bX<16)commando='R';
switch (commando){
case 'R':
if(cX>-1)cX++;
break;
}
if(bX>178 && bX<184)commando='0';
switch (commando){
case 'O':
cX=4;
cY=4;
break;}
if(bY>0 && bY<8)commando='U';
switch (commando){
case 'U':
if(cX<32)cY--;
break;
}
if(bY>345 && bY<350)commando='D';
switch (commando){
case 'D':
if(cY<8)cY++;
break;
}
}
if(B==2){
lc.setLed(A,By,Bx,true);
static int bX;
static int bY;
static char commando='0';
do {
bX=516-analogRead(aX);
Serial.print("bX position= ");
Serial.println(bX);
delay(dt);
bY=507-analogRead(aY);
Serial.print("bY position= ");
Serial.println(bY);
delay(dt);
}while ((bX)>30 && (bX)<20 && (bY)>30 && (bY)<20);
if(bX>350 && bX<360)commando='L';
switch (commando){
case 'L':
if(cX<32)cX--;
break;}
if(bX>10 && bX<16)commando='R';
switch (commando){
case 'R':
if(cX>-1)cX++;
break;
}
if(bX>178 && bX<184)commando='0';
switch (commando){
case 'O':
cX=4;
cY=4;
break;}
if(bY>0 && bY<8)commando='U';
switch (commando){
case 'U':
if(cX<32)cY--;
break;
}
if(bY>345 && bY<350)commando='D';
switch (commando){
case 'D':
if(cY<8)cY++;
break;
}
}
if(B==3){
lc.setLed(A,By,Bx,true);
static int bX;
static int bY;
static char commando='0';
do {
bX=516-analogRead(aX);
Serial.print("bX position= ");
Serial.println(bX);
delay(dt);
bY=507-analogRead(aY);
Serial.print("bY position= ");
Serial.println(bY);
delay(dt);
}while ((bX)>30 && (bX)<20 && (bY)>30 && (bY)<20);
if(bX>350 && bX<360)commando='L';
switch (commando){
case 'L':
if(cX<32)cX--;
break;}
/*do {
bX=516-analogRead(aX);
bY=507-analogRead(aY);
}while (abs(bX)<5 && abs(bY)<5);*/
if(bX>10 && bX<16)commando='R';
switch (commando){
case 'R':
if(cX>-1)cX++;
break;
}
if(bX>178 && bX<184)commando='0';
switch (commando){
case 'O':
cX=4;
cY=4;
break;}
if(bY>0 && bY<8)commando='U';
switch (commando){
case 'U':
if(cX<32)cY--;
break;
}
if(bY>345 && bY<350)commando='D';
switch (commando){
case 'D':
if(cY<8)cY++;
break;
}
showPixel(cX, cY);
do {
bX=516-analogRead(aX);
bY=507-analogRead(aY);
}while (abs(bX)<5 || abs(bY)<5);
}
void showPixel(int x, int y); {
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
lc.setLed(3, x, y, true);
lc1.setLed(3, x, y, true);
lc2.setLed(3, x, y, true);
lc3.setLed(3, x, y, true);}
}
type or paste code here
#include "LedControl.h"
const byte 8x8devices= 16 ; // how much single 8x8 matrix's are together
const byte DIN = 11 ;
const byte CS = 10;
const byte CLK = 13;
LedControl lc(11, 13, 10, 8x8devices); //10 is to CLOCK, 9 = CS, 8=DIN 4 panel daisy chained, but power better parrallel
const byte aX = A0;
const byte aY = A1;
const byte treshold = 15;
void setup() {
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
}
void loop() {
const byte maxX=4*8-1;
const byte maxY=8x8devices/4*8-1;
static byte cX = 24;
static byte cY = 0;
static int bX;
static int bY;
static char commando = '0';
do {
bX = analogRead(aX) - 512;
bY = analogRead(aY) - 512;
} while (abs(bX) < treshold && abs(bY) < treshold);
if (bX < -treshold)commando = 'L'; // if movement direction of joystick
if (bX > treshold)commando = 'R';
if (bY < -treshold)commando = 'D'; // not correspond to them of pixel
if (bX > treshold)commando = 'U'; // then here swap Letters
switch (commando) {
case 'L':
if (cX > 0)cX--;
break;
case 'R':
if (cX < maxX)cX++;
break;
case 'U':
if (cY > 0)cY--;
break;
case 'D':
if (cY < maxY)cY++;
break;
}
showPixel(cX, cY);
commando = '0';
do {
bX = analogRead(aX) - 512;
bY = analogRead(aY) - 512;
} while (abs(bX) > treshold || abs(bY) > treshold);
}
void showPixel(int x, int y) {
lc.clearDisplay(0);
lc.setLed(3 - x / 8 + 4 * (y / 8), x % 8, y % 8, true);
}
updated
Hello Kolaha,
The code has been fixed, however not by me. My manager hepled.
We kept the same wiring, that is, 3 Digital PIN for each LED panel.
It is working fine.
Below is the code.
Thank you soo much for sharing your knowledge and expertise in Arduino.
//We always have to include the library
#include "LedControl.h"
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
***** Please set the number of devices you have *****
But the maximum default of 8 MAX72XX wil also work.
*/
LedControl lc=LedControl(13,11,12,4); //DIN, CLK, CS
LedControl lc1=LedControl(10,8,9,4);
LedControl lc2=LedControl(7,5,6,4);
LedControl lc3=LedControl(4,2,3,4);
/* we always wait a bit between updates of the display */
unsigned long dt=0;
const byte aX=A0;
const byte aY=A1;
int cur_x;
int cur_y;
/*
This time we have more than one device.
But all of them have to be initialized
individually.
*/
void setup() {
Serial.begin(9600);
//we have already set the number of devices when we created the LedControl
int devices=lc.getDeviceCount();
//we have to init all devices in a loop
for(int address=0;address<devices;address++) {
/*The MAX72XX is in power-saving mode on startup*/
lc.shutdown(address,false);
lc1.shutdown(address,false);
lc2.shutdown(address,false);
lc3.shutdown(address,false);
/* Set the brightness to a medium values */
lc.setIntensity(address,15);
lc1.setIntensity(address,15);
lc2.setIntensity(address,15);
lc3.setIntensity(address,15);
/* and clear the display */
lc.clearDisplay(address);
lc1.clearDisplay(address);
lc2.clearDisplay(address);
lc3.clearDisplay(address);
}
// set position to the middle
cur_x=15;
cur_y=15;
UpdatePixel(cur_x,cur_y);
}
void loop() {
int bX;
int bY;
bX=337-analogRead(aX);
//Serial.print("bX = ");
//Serial.println(bX);
//delay(dt);
bY=337-analogRead(aY);
//Serial.print("bY = ");
//Serial.println(bY);
//delay(dt);
if (bX<-100&&cur_x>0){
cur_x--;
UpdatePixel(cur_x,cur_y);
}
if (bX>100&&cur_x<31){
cur_x++;
UpdatePixel(cur_x,cur_y);
}
if (bY<-100&&cur_y>0){
cur_y--;
UpdatePixel(cur_x,cur_y);
}
if (bY>100&&cur_y<31){
cur_y++;
UpdatePixel(cur_x,cur_y);
}
delay(dt);
}
void UpdatePixel(int x, int y){
//read the number cascaded devices
int devices=lc.getDeviceCount();
int B=abs(y/8);
int A=3-abs(x/8);
int Bx=x%8;
int By=y%8;
for(int address=0;address<devices;address++) {
/* and clear the displays */
lc.clearDisplay(address);
lc1.clearDisplay(address);
lc2.clearDisplay(address);
lc3.clearDisplay(address);
}
if(B==0){
lc.setLed(A,By,Bx,true);
}
if(B==1){
lc1.setLed(A,By,Bx,true);
}
if(B==2){
lc2.setLed(A,By,Bx,true);
}
if(B==3){
lc3.setLed(A,By,Bx,true);
}
}
//Deprecated code
/* Use this code to loop through all of the LEDs
//we have to init all devices in a loop
for(int row=0;row<8;row++) {
for(int col=0;col<8;col++) {
for(int address=0;address<devices;address++) {
delay(delaytime);
lc.setLed(address,row,col,true);
delay(delaytime);
lc.setLed(address,row,col,false);
}
for(int address=0;address<devices;address++) {
delay(delaytime);
lc1.setLed(address,row,col,true);
delay(delaytime);
lc1.setLed(address,row,col,false);
}
for(int address=0;address<devices;address++) {
delay(delaytime);
lc2.setLed(address,row,col,true);
delay(delaytime);
lc2.setLed(address,row,col,false);
}
for(int address=0;address<devices;address++) {
delay(delaytime);
lc3.setLed(address,row,col,true);
delay(delaytime);
lc3.setLed(address,row,col,false);
}
}
}
*/
Sorry for the late.
Now, I am working on interfacing this Arduino to NI DAQ and control by LABVIEW.
