Should this code work? matrix + joystick

I have made a program in which with the joystick turn on the LEDs of the matrix 8x8. I am not sure if what I have done is correct. I want to use the joystick button to turn on the led off the current position and keep it on. Should the following code work correctly?

int ValorY = 0;
int ValorX = 0; 
#include "LedControl.h" 
LedControl lc=LedControl(13,12,11,1); 


void setup() {
  Serial.begin(9600);

  pinMode(8, INPUT); 
  lc.shutdown(0,false);
  lc.setIntensity(0,8);// sets brightness 
  lc.clearDisplay(0);// clear screen

}

void loop() {
  ValorY = analogRead(A1);
  ValorX = analogRead(A0);
  char x_translate = map(ValorX, 1023, 0, 7, 0); 
  char y_translate = map(ValorY, 1023, 0, 0, 7);
    
  Serial.print("ValorX = ");
  Serial.print(ValorX, DEC);
   Serial.print("ValorY= ");
  Serial.print(ValorY, DEC);
  Serial.print(", x = ");
  Serial.println(x_translate);
  Serial.print(", y = ");
  Serial.print(y_translate); 
    lc.clearDisplay(0);
    lc.setLed(0,x_translate,y_translate,true);  
  delay(150); 

  if ( digitalRead (8)== HIGH){          
    lc.setLed(0,x_translate,y_translate,true);
    }


Please Auto format your code in the IDE, use Copy for forum in the IDE and paste it here so that it is code tags to make it easier to read and copy for examination

And then run it and see if works or not. Arduinos are ideal for testing simple circuits. Why worry about what should theoretically happen, just test it and then tell us if there any problems.

We have no real idea what components you are using so we'd just be guessing.

Steve

The problem is that the matrix is probably doesn't works correctly.

Hi, @mrsamu18
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
https://forum.arduino.cc/index.php?topic=712198.0
Then look down to "code problems" about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you also post an image of your project, so we can see your component layout?
What hardware are you using?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

I have uploaded what you have asked me. All the pictures are in the post. Thanks for your attention.

WHERE???
Oh in your first post, please do not go back and edit and add to old and in particular Original Posts.
Posting in a new post would help with the flow of the thread if someone else starts to read it.

What do you mean "probably doesn't works correctly"?
What does you code do to the display?

Tom... :grinning: :+1: :coffee: :australia:

Have you tried a simple program to see if the matrix works, that is an example you didn't write yourself or modify?

And this

"I want to use the joystick button to turn on the led off the current position and keep it on."

might make sense to you, but it doesn't make sense to me and I would risk going out on a limb to say it just doesn't make sense to anyone. But you.

a7

I think I haven’t explained well, I wanted to say with the movement of the joystick move around the leds from the matrix but with the joystick button turn on the led in the current position. The program is modified and yes I have tried a simple program for only turn on a led in a specific position from the matrix but didn’t work.

#include "LedControl.h"
LedControl lc=LedControl(13,12,11,1);

void setup() {

  lc.shutdown(0,false);
  lc.setIntensity(0,8);
  lc.clearDisplay(0);

}

void loop() {

 lc.setLed (0, 2, 4, true);

}

I think the matrix is not working well but i'm not sure. Because I tried to use a simple code for only turn on a led from the matrix but didn't work. The code is for paint the leds from the matrix.

Find an example that uses the matrix.

Your simple program looks plausible, are you sure you have it wired correctly and with proper and adequate connections to power?

a7

Hi,
Did the display come presoldered or did you solder the LEDMatrix to the PCB?

Tom... :grinning: :+1: :coffee: :australia:

Hi,
Have you tried the LCDDemoMatrix example in the IDE?
I would connect your matrix up as per the examples suggestions.

Tom... :grinning: :+1: :coffee: :australia:

I had to solder the pins to the matrix.

I haven't used it, what is it for??

Hi,
Are you sure you connected the display the correct way around?

Look at the datasheet for the dot display to find out how to orient it.

Tom.... :grinning: :+1: :coffee: :australia:

The example code is a proven bit of code that should work on a correctly wired display.
Even though it might not do what you require it will prove the integrity of your circuit.

Tom.... :grinning: :+1: :coffee: :australia:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.