Just a quick helping thing.
So I wanna multiply multiple variables with a variable, but is there a way I can do It easier than:
var1multipltyVar;
var2multiplyVar;
vari3multiplyVar;
......
something like this:
(var1,var2,var3)multiplyVar;
So I have to change the multiplyVar only once.
thanks
29 Replies
I know you can do this for setting pinModes with a for loop, but with variables idk.
@TheStudier you can make a function.
maths?
you mean
So i am understanding you.
You have a value. We will call it wart.
And you have a bunch of varables, say a through t and you need them all to be multiplied by wart right?
indeed
yes
Yes. So you make a function to do that
Its like 3 lines of code
okay
thanks
Is interger math ok?
the variables are floats
Ok. So u need float math.
So you have a void setup. And a void loop right?
yep
Make a new function in betweene them.
void maths();
and I put maths(); in void loop
Im actually wondering why I need to make a new function, cant the code to just void loop? Or does the function I made work differently to void loop
Now in your code just pass your varables into that function. And pull the data out of that function
hmm
whose is better omg??
That should be fine
hmm
float myFloat[6];
void thing() {
for (int i = 0; i < 6; i++) {
myFloat[i] = 22.0 / 7.0 * i;
}
}
so what is the 22.0/7.0
how can i use code block
I thought the values were dynamic. Hence the function.
Thats why I asked a chain of varables if its just a bunch of statics then its pointless just code the pre processor to set them ino
cpp
oaky
so does the original float change?
okay
So its 3.14, then 6.28 ...... so just set the values
damn why cant arduino just have code like this cpp
Because its bad form
okay
You can make a function to do that. 😉
Can you if those numers are variables?
That what I asked, hopefully you undersoots, I mena that was my original question.
You can but then you slow cpp down
Thats why what it takes python 37 days to do cpp does in 15 secconds.
Is because of this exactly
okey
thank you guys
Yw. Close thread please.
close!
!close
!how