8x8 dot matrix

#include <LedControl.h>

const int posX = A0;
const int posY = A1;
LedControl lc= LedControl(12, 11, 10, 1);

void setup() {
lc.shutdown(0,false);
lc.setIntensity(0,5);
lc.clearDisplay(0);
}

void loop() {

int x;
x = 0;

int y;
y = 0;

lc.setLed(0, x, y, true);

do {
if (analogRead(posX) > 1000) {
lc.clearDisplay(0);
++x;
if(x > 7) {
x--;
}
lc.setLed(0, x, y, true);
delay(100);
}
else if (analogRead(posX) < 100) {
lc.clearDisplay(0);
x--;
if(x < 0) {
++x;
}
lc.setLed(0, x, y, true);
delay(100);
}
}
while (515 < analogRead(posX) < 525);

do {
if (analogRead(posY) < 100) {
lc.clearDisplay(0);
++y;
if(y > 7) {
y--;
}
lc.setLed(0, x, y, true);
delay(100);
}
else if (analogRead(posY) > 900) {
lc.clearDisplay(0);
y--;
if(y < 0) {
++y;
}
lc.setLed(0, x, y, true);
delay(100);
}
}
while (485 < analogRead(posY) < 515);
}

This code is the code that moves the LED of the 8x8 dot matrix by the joystick.
When this code is executed, the X-axis moves normally at the 8x8 dot matrix, but the Y-axis does not.
I want to know which part is wrong.

And my English is not good, so I use a translator.
Therefore, we ask for your understanding as it may affect communication.


I'll change the question.
I changed the position of the code on the X-axis and the code on the Y-axis.
This time, the Y-axis moves, but the X-axis does not move.
It seems to be a problem because do while statement cannot be used at the same time.
What do you think there is?

You can not have multiple comparisons in C, like:

while (515 < analogRead(posX) < 525);

it has to be like

int readingX = analogRead(posX);
while (515 < readingX and readingX < 525);
while (515<readingX && readingX<525);

Datman:

while (515<readingX && readingX<525);

I prefer the keyword 'and', it's more human readable.

Does it work in C?...

Datman:
Does it work in C?...

It works in this C, and most modern C compilers. It's an official feature of the language now.

int x;
x = 0;

int y;
y = 0;

:o

Datman:
Does it work in C?...

You're working in C++, so is it important?

Ok. Edit: Does it work in C++?...

I used the above method, but there was another problem.

First of all, there's only one place that light can move.
Also, if the joystick does not move, it returns to its original position.
In addition, there are times when the moving compartment flashes, and there are times when both spaces are at the same time...

Is there any other way to use do-while at the same time?

OP, please don't PM me with questions. I specifically request that in my avatar signature. Post them here, as there are dozens more people that can help you.

Datman:
Ok. Edit: Does it work in C++?...

Is is so difficult for you to try it?

In these days, it's impossible! :slight_smile:

Datman:
In these days, it's impossible! :slight_smile:

How so ?

Do not use the 'for' code.
How do I make the two 'do-while' codes work at the same time?
I've also written 'and' to the condition, but more errors have occurred.

It isn't really impossible, but I haven't here an Arduino board, then I should reprogram via USBASP the GPS/DDS generator and look at the results via the LCD.

Datman:
It isn't really impossible, but I haven't here an Arduino board, then I should reprogram via USBASP the GPS/DDS generator and look at the results via the LCD.

Use the online IDE

title_:
Is there any other way to use do-while at the same time?

You may be able to simply combine the x and y actions like:

do {
 if (analogRead(posX) > 1000) {
    ++x;
   if(x > 7) {
     x--;
   }
if (analogRead(posY) > 1000) {
    ++y;
   if(y > 7) {
     y--;
   }
...

What is your first language? The forum has sections for several languages. Perhaps you will be better understood if you post in your own language in the correct forum section.

Why do you need to? The loop function loops anyway. Just read your two axes at the start of loop and adjust which LED is lit based on what you see.

duplicate post
https://forum.arduino.cc/index.php?topic=700468.0