Im jazzy gerard 2 day old new to the programming world from arduino.
I alreay now how to program in JAL but I find the arduino programming and all types of boards
very interesting, user friendly and easy to use!
now I'm busy with making a summary of all the refrences on the arduino website. but i have e problem with the return.
let me state my question with an example
int checkSensor() {
if (analaogRead(0) > 400){
return 1;
else
return 0;
{
{
so if i understand the explanation this means if the value from the reading on analog pin 0 is grater then 400 the program goes back to the beginning and starts over from there and a 1 is returned. What returns the 1? the checksensor? the analog reading?
probably for you guys this is easy but i'm just a beginner!
Right... The return statement sets the value that is returned from the function call. The function terminates at that point.
So, if you create the function:
int checkSensor() {
if (analaogRead(0) > 400) {
return 1;
} else {
return 0;
}
}
you can then call that function and use the return value in some way. When you call the function, either 1 or 0 will be returned to where you called the function. The function is in effect replaced by the return value.
For example, if you then had the code:
int sensorHigh = checkSensor();
the variable sensorHigh would either contain a 0 or a 1 depending on the value of analog pin 0. In effect the code is equivalent to one of:
int sensorHigh = 1;
or
int sensorHigh = 0;
depenging on the value of analog pin 0.
The definition of the checkSensor() function (int checkSensor()) includes the "return type" - int in this case. This is the kind of variable that the function can return - whole numbers between -32768 and 32767 for this example.