Whats this thing?
So if I understand correctly when the code is in print(measureVal), it executes the void print loop and inside that loop float result is the same as measureVal, because of : print(measureVal);
But the thing I don't understand is what is the float readTemp(int pin) {... } Like it's not a loop, it looks like a variable. How can it not be inside a loop. And what the actual freaking donut does this thing do?
thanks
void setup() {
Serial.begin(9600);
}
void loop() {
float measureVal=readTemp(A0);
print(measureVal);
delay(1000);
}
float readTemp(int pin) {
int reading=analogRead(pin);
float voltage=(5.reading)/1023.;
float temperature=(voltage-0.5)100;
return temperature;
}
void print(float result) {
Serial.print("Temp: ");
Serial.println(result);
}
70 Replies
Ok start with the basics algebra.
What is this called:
x=10+y
@TheStudierthat is a equation or is it
By the way you have been at this long enough to have learnt all of this.
YES.
so what would the value of x be?
I have had some breaks
so
who knows
Right what if we did this:
x=10+2
12!
Ok what IF. we had NO x.
So we had this:
[blank]=10+2
blank means there is n9thing there FYIthe variable is 12 idk
right but there is no place to PUT the SUM, so then nothing happends.
Make sence?
yes
ok NOW lets connect this
what is this:
looop
no.
damn
that is a void without a name
im not the bigtest bulb
its a "function", same as:
x=10+2
oh
ok so what does the word "void" represent?
x
no idea
Look it up, get a dictonary
the function does not return a value
well thats TRUE, but void is emptiness:

oh so that what you meant
OK so now you know what a function is.
And now you know what a void is, lets move forward.
what does THIS function return?
nothing?
BINGO
OK now what if we did this:
does it return x? hmm
but where
well it will TRY to return x. but as its returing it into a VOID,, what do you feel is going to happen to x ?
the x will be never seen again
RIGHT
so what would we need to do to be able to get X out of this function?
remember in this example X will alwaysbe an int value
write it outside the loop
xd
no, because there is no LOOP
oh sorry forgot
have you ever played catch? with a ball and a friend?
sure
i can throw good
ok so you toss the ball to your friend, they catch it and throw it back and you catch it right?
sometimes that happens tes
yes*
What would happen IF you tossed the ball to your friend, but your friend VANISHED into NOTHINGNESS [void]
The ball would just fly out there
not return
BINGO, so what is needed to "catch" the ball, back and forth?
TWO people
looking at this again.
we are CLEARLY making a ball. X
And we are CLEARLY trying to TOSS the ball.
return(x);
But something needs to change in this function for the ball to GO somewhere.
Think a few minutes of what we need to change, Ill BRBtake out the void?
And replace void with?
some variable i guess
variable type
indicator
Great
pleaes
What type of varable are we TOSSING.
INT
Ok so fix the example function.
inr theStudier() {
int x = 2 + 10;
return(x);
}
?
Ok now.
Look back at this.
https://discord.com/channels/420594746990526466/1416515292355629198/1416515292355629198
What do you see?
so float measure val =readTeamp(A0). and then float readTemp(int pin) does stuff to and return the value
and as its a float, what type of value is it "TOSSING"
floating value, pretty easy to toss as its already floating
right.
So now we go the the secondpart of the game of "catch".
You have tossed the int to your friend, but now YOU need to be ready to receive something back.
[in this example YOUR the function
inr theStudier()
so How can we get ready to CATCH a value as a function.
We learnt how to TOSS, but catching.int theStudier(someting here?)
So reformat that example function to receive 2 values, add the values, then return the sum of the two values please.
Fix this:
Take your time if you must
void theStudier(int sausage, int IhaveToRun) {
int x = sausage, IhaveToRun;
return(x);
}
?
close, your not adding them currently.
+ not ,
and there is another error.
Dont guess, think it THROUGH
but should i change the void
You know the answer to this. If not then review this convo'
int theStudier(int sausage, int IhaveToRun) {
int x = sausage,+IhaveToRun;
return(x);
}
Ok add it to your code, and use it., see if it will work.
BTW if you realy need to go, thats fine, you can come back to this convo when ever.
no
I have time
Remember your goal is to LEARN, so IF you have issues, or if you dont get the results you expect try and work through it.
I have given you all the tools you should need to acomplish this oal.