Y variable known when x variable known

So make a two dimensional array. Each element of the main array is a sub-array of two numbers, x and y. The main array you make as large as needed to hold the number of data pairs your sketch needs to remember.

Google "Arduino two dimensional array"; this will turn up pages like this one: Arduino - Multi-Dimensional Arrays
Do some reading and implement this in your sketch.

You can loop through an array using a for-loop. You can have your sketch maintain an index variable that "remembers" the most recently written array element, for instance.

Whether the table is loaded at compile time, boot time, randomly as observations happen, etc., it still sounds like a:

@petercl14
Could you extend this code for some another values of x? Say this way:


if (x==9)    {z=y;}

if (x==10)    {....

if (x==11)    {....

please finish the code inside a curly brackets.

It could to help us to understand your problem.

I think OP's saying that the y values are not known at compile time, and then there might be confusion about how to save the to-be-read-later y values somewhere and recover them sometime after the reading.

Does a set of data exist? Graph it for trends. I find it strange that this super-complex, mystery formula does not have a formula, or data, or a name. If nothing has an initial "x" and "y" is unknown and dependent on an arbitrary time of day:

y = random (x);

Is as good as anything.

i'm guessing that the code does some sort of analysis of the x/y data

Could be. It's hard to tell. Maybe some analysis is supposed to happen during the downloading? Or after all the data has been downloaded? And then an x occurs.

Either way, it's definitely:

Strictly speaking, it's an xy problem rather than an XY problem :grinning:

since it spits the data out maybe it could spit it into a data logger :wink:

Okay... At 50 posts... so it's time to get creative. OP wants to play "my code is super top confidential so I will not release anything useful, but expect help".... I sum and present what I observe... Date and time effect output, and the input is unknown, so OP is running a card skimmer and is actively trying to extract card numbers from a rolling cypher. How close am I? RSVP with useful information, including data dump.

Its not worth to spend any more time on this.
The TO is not responding direct questions.
So it might not be important for him to get help.
Please just let this thread go down the history.

Because he can't. He unable to explain the problem because there is no problem at all.

I maintain my position.

I think you have got to the crux of the problem Bob. I don't need to save x,y values to look them up later as you suggest. This is why I have not been responding to suggestions of an array. This would be wasting a lot of computer space.
The x variable is used to do something and the y another thing.
Then other values of x,y being different values will do something else.
Once the thing, whatever it is, is done it becomes historic with no need to be saved.

Having seen that description I don't see what the problem is. You receive x and y and use their values. Job done. Later you receive different values of x and y and use them instead. Where is the problem ?

Why do you need any if statements? Did you mean:

if( x==9 && z==y ) {....}

If you do different things with y depending on x, then switch(x)...case is the way to go. Otherwise:

the problem may be my revised coding Bob. which now is;
for (x=0; x< 100; x++){
y;
x;
}
In the 'for' statements you always get the x++ tacked on the end. This may not be necessary and may just not work.
I could try this;
for(x=0;x<100;{
y;
x;
}
x goes through the values of 0-100 in steps of one. y may be 5 when x is 55. x is tested and the 'for' statement is exited when x >=100.
However this may not be valid coding without x++.

That particular code will be a (perfectly valid) endless loop because x is set to 0 at the beginning, and is never changed. It will not go through the values 1-100 because it is never changed from zero.

for (x=0; x< 100; x++){
y;
x;
}

What do you expect that for loop to do, bearing in mind that you have previously said

This is one of the most useless codes I've ever seen.

@petercl14 , do you realize that the operators in the loop

y;
x;

do nothing?
And most likely the compiler will simply throw this loop out of the code during optimization?