Hi guys.
I've written a rather long complicated code in which i am noticing some misbehavior i am not really able to explain.
I tried recoding this part of the code in a very very basic manner, so that the problem can be reconstructed easily. (This is why i did such a stupid detour for such a short code....the "real" code is much longer and more complicated, and thats why i want to move the procedure to a different void....so please dont comment on "why not move it to the code itself").
Basic problem: I want to fade a byte (0-255) from a predefined startvalue to a predefined stopvalue, using a predefined speed and predefined amount of steps.
Solution: Take the difference between the start and the stopvalue, divide it by the amount of steps, and then hand the value over to the function. After each delay (determined by the preselected speed), a counter is increased, and the target value is equal to startvalue plus number of increments times each steps increment.
Suspected problem: each step might be a very small number (e.g. 0.3), but the amount of steps make it add up to a rather large number, so i need a certain precision. I picked float. (if i write small numbers to a byte i get either 0 or 1). If i add this to my void(), i get the Error:
'stepincrement' was not declared in this scope
This is the Code:
byte ValStart=30;
byte ValMax=250;
byte FadeSteps=50;
byte FadeSpeed=10;
byte i=0;
byte currentcolor;
void setup() {
float stepincrement=(ValMax-ValStart)/FadeSteps;
Serial.begin(115200);
}
void loop() {
fadeRun();
delay(FadeSpeed);
}
void fadeRun() {
if (i<=FadeSteps) {
i++;
currentcolor=ValStart+(i*stepincrement);
Serial.println(currentcolor);
}
}
If now i move the calculation from within the setup to within the void, it works fine. (I am trying to avoid this, as the real calculation is rather complex, and i would like to save a loooooot of processing time by precalculating it instead of doing all the math over and over in each loop.
byte ValStart=30;
byte ValMax=250;
byte FadeSteps=50;
byte FadeSpeed=10;
byte i=0;
byte currentcolor;
void setup() {
Serial.begin(115200);
}
void loop() {
fadeRun();
delay(FadeSpeed);
}
void fadeRun() {
if (i<=FadeSteps) {
i++;
currentcolor=ValStart+(i*((ValMax-ValStart)/FadeSteps));
Serial.println(currentcolor);
}
}
If now i move the calculation from within the setup to within the void
First, after 87 posts you should know they are called FUNCTIONS, the are not called VOIDS! 
You declare stepincrment inside setup(), this means its scope is only inside setup(), which means it is not visible to any other function, including loop(). Declare stepincrment at the top, along with all your other variables, then it will have global scope and be visible everything.
I suspect you are right about using a float, I suspect you need integer values.
Although not the cause of your problem please study blink without delay, which is in the examples in the IDE under digital and apply the lessons learnt to your code. Delay might be working OK for you now in simple code, but the more complex your code gets the more delay will cause you problems.
In answer to the question "my code is not very responsive and I don't know why", which you will be asking in a month or 3; "It's because of all the delays".
float stepincrement=(ValMax-ValStart)/FadeSteps;
ValMax, ValStart and FadeSteps are ALL defined as byte variables. They can each have only an INTEGER value from 0 through 255. The calculation of (ValMax-ValStart)/FadeSteps will be carried out using INTEGER values, and the final result of the calculation will be converted to a float. How will that work out?
ValMax-ValStart) = 250 - 30 = 220
(220)/50 = 4
So, stepincrement will calculated as 4.0. It will NEVER contain a non-integer value, like 0.3, so no point making it a float.
If you WANT stepincrement to contain a non-integer value, you need to force the calculation to be done in floating point:
float stepincrement=((float)ValMax-ValStart)/FadeSteps;
Now stepincrement will calculated as 4.4:
ValMax - ValStart = 250.0 - 30 = 220.0
(220.0) / 50 = 4.4
Regards,
Ray L.
@Perry: Even after 1000 posts, if noone tells me i wont know......
But moving the calculation to outside the setup actually did solve the problem, thanks. Actually declaring it outside and filling it in the setup does so too.
(And i am using the blink without delay function......but that would have made the code here more complicated without making it easier to read
)
@Ray: youre right! That modification actually did also solve some jumping i have been observing. Thanks!!!
@Perry: Even after 1000 posts, if no one tells me I won't know......
True of course but I kind of thoght you'd have noticed 
But moving the calculation to outside the setup actually did solve the problem, thanks
I think you are confusing 2 things:
Variables have a property called 'scope', which defines what can see them. I think you are confusing scope with where you do the calculation. You declare lots of variables at the top as bytes, but for some reason I don't understand decided to declare stepincrment inside setup(). You can do the calculation inside setup(), but you must declare the variable at the top, which makes its scope global, which is C speak for visible everywhere.
I'm not going to try to teach you about scope, use your favourite search engine and search for something like C variable scope and see what comes up.
Ahhhhhh i see. That helped understand what you wanted to tell me. I was sort of confused as i thought everything i do in "setup" would be valid for everything.
OK one more point of confusion:
I want to create a series of matrixes, which have to change in size if a setup parameter is changed.
I can do it manually by declaring it every time in every matrix, but i'd love to change just one value and the rest goes by itself.
example Works for 50*3 matrix:
byte Amount=50;
byte MatrixAmount[50][3];
Doesnt work:
byte Amount=50;
byte MatrixAmount[Amount][3];
const byte Amount=50;
byte MatrixAmount[Amount][3];
What AWOL said or:
#define Amount 50
byte MatrixAmount[Amount][3];
Obviously you've not said why you want to do this but consider if you need to or if you can just define the largest array (they are called arrays) you will ever need and just use that. I'm not saying you should do that, just suggesting it as a possibility.
Yeeeah i'm being picked on that in my other thread as well.....
https://forum.arduino.cc/index.php?topic=651092
As i explained there, its a veerrrrry basic programming question which did not match the topic at all, so in the sake of other newcomers i decided to place it in a more dedicated section for the topic at hand 