A
Arduino•4mo ago
TheStudier

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
TheStudier
TheStudierOP•4mo ago
I know you can do this for setting pinModes with a for loop, but with variables idk.
DaDev
DaDev•4mo ago
@TheStudier you can make a function.
TheStudier
TheStudierOP•4mo ago
maths? you mean
DaDev
DaDev•4mo ago
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?
TheStudier
TheStudierOP•4mo ago
indeed yes
DaDev
DaDev•4mo ago
Yes. So you make a function to do that Its like 3 lines of code
TheStudier
TheStudierOP•4mo ago
okay thanks
DaDev
DaDev•4mo ago
Is interger math ok?
TheStudier
TheStudierOP•4mo ago
the variables are floats
DaDev
DaDev•4mo ago
Ok. So u need float math. So you have a void setup. And a void loop right?
TheStudier
TheStudierOP•4mo ago
yep
DaDev
DaDev•4mo ago
Make a new function in betweene them.
TheStudier
TheStudierOP•4mo ago
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
DaDev
DaDev•4mo ago
float multiplyer(float top, float bottom){
return(top * bottom);
}
float multiplyer(float top, float bottom){
return(top * bottom);
}
Now in your code just pass your varables into that function. And pull the data out of that function
TheStudier
TheStudierOP•4mo ago
hmm whose is better omg??
DaDev
DaDev•4mo ago
That should be fine
TheStudier
TheStudierOP•4mo ago
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
DaDev
DaDev•4mo ago
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
TheStudier
TheStudierOP•4mo ago
cpp 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
cpp 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
cpp oaky so does the original float change? okay
DaDev
DaDev•4mo ago
So its 3.14, then 6.28 ...... so just set the values
TheStudier
TheStudierOP•4mo ago
damn why cant arduino just have code like this
cpp pinMode(1,2,3,4,5,6,OUTPUT);
cpp pinMode(1,2,3,4,5,6,OUTPUT);
cpp
DaDev
DaDev•4mo ago
Because its bad form
TheStudier
TheStudierOP•4mo ago
okay
DaDev
DaDev•4mo ago
You can make a function to do that. 😉
TheStudier
TheStudierOP•4mo ago
Can you if those numers are variables? That what I asked, hopefully you undersoots, I mena that was my original question.
DaDev
DaDev•4mo ago
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
TheStudier
TheStudierOP•4mo ago
okey thank you guys
DaDev
DaDev•4mo ago
Yw. Close thread please.
TheStudier
TheStudierOP•4mo ago
close! !close !how

Did you find this page helpful?