Go Down

Topic: Multi-Dimensional Arrays, Retreving data. (Read 336 times) previous topic - next topic

Krzy1999

Sorry for posting in the wrong forum section i'm preatty new to this.

I have made a multidimentional array that look like this:

//Buttom right
int ledMatrixA[8][9] ={ 
{B11111110,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11111101,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11111011,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11110111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11101111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11011111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B10111111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B01111111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001}  };

I want to be able to keep track of what position im on and update it with a press of a button. I want to explain more and awnser your questions if you can join discord would be lovely. :) thanks in advance https://discord.gg/vmCDUf


lastchancename

#16
May 22, 2018, 12:14 am Last Edit: May 22, 2018, 12:17 am by lastchancename
Change your (16-bit) ints to (8 bit) bytes - save half your memory!

Code: [Select]
byte readvalue;

// Buttom right
int ledMatrixA[8][9] ={ 
{B11111110,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11111101,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11111011,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11110111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11101111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B11011111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B10111111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001},
{B01111111,B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001}  };

// only you can find these...
byte x = firstIndex;
byte y = secondIndex;

readvalue = ledMatrixA[x][y];

// use readvalue for whatever you want...
Ask the right question, which can be hard for beginners, but this doesn't mean that google is broken.
Experienced responders have a nose for laziness, (they were beginners once)... expecting the poster to contribute to the learning experience.

Coding Badly


@Krzy1999, please do not cross-post.  Threads merged.


adwsystems

#18
May 22, 2018, 03:19 am Last Edit: May 22, 2018, 11:48 am by adwsystems
So im coding some simple code. but have no idea on how to actualy begin or make this code. Im willing to pay you if you could help me with coding this shit. I'v made a multidimentional array. I want to be able to controll and update the position the the array. I'm using analog buttons. I can help you on what i've written allready and explain and awnser all of you'r questions over Teamspeak/Discord/Skype etc.
What are analog buttons?

What you want isn't at all difficult. The wiring is far more difficult than the program will be. Someone else can write the program, but since they don't have the hardware, they can't test it. It would be still up to you to debug their program. I'm sure you can write the program, but you may need to reframe your thinking. The trick is to take it one step at a time.

1. Write a sketch that lights one LED.
2. Write a sketch to read the four buttons (don't forget to explain what analog buttons are, in the picture they look like standard on/off 0/1 push buttons)
3. Add the if statements to combine #1 and #2 (don't forget to not let the position go <0 or >15)

We can walk you through it. Let's begin.

Decide on where position x=0, y=0 is. Lower left?

Decide where you want the first LED to light.

Now I hate to say this, but start a blank sketch.

Write a sketch that turns on the one led at the start position (hint: declare two global variables posX and posY and set them to you selected start position).

Post your sketch when you have that done. Then we can walk through the next step.

This may sound kind of lame but trust me this process works. I have taught dozens of people and written hundreds of programs using it.

Go Up