Robojax

Lesson 56 : What is a function? | Arduino Step By Step Course

Part 6: Arduino Practiall Programming

In this lesson we learn how what a function is and how to define it. We learn about return type, about arguments and parameters.


  /*
  * S06-01 
  Lesson 56 : What is a function? | Arduino Step By Step Course
 * This is Arduino sketch to demonstrate "functions" in Arduino
 Please watch video for full details: https://youtu.be/KRTnaSYOEmQ
 
 * Written by Ahmad Shamshiri for Robojax.com and Robojax YouTube channel
 * on Jan 03, 2019 at 15:25 in Ajax, Ontario, Canada


  
 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

const float voltage = 3.3;

void setup() {
   // Robojax Arduino floating points
  Serial.begin(9600);// initialize the Serial Monitor
}




void loop() {
  //3.141592
  Serial.println(    pi(), 10  );
  

  //delay(1000);
    
}

/*
  printText: prints the text on Serial monitor
  
  @param t is String text
  @ returns nothing
 */
void printText(String t)
{

   Serial.println(t);                   
}


/*
 * getDays is calculation the number of days in a year
 * @param a is integer 
 * @param returns integer value of number of days
 */
int getDays(int a)
{
  return (a * 365);// multiply  a by 365 to get number of days and return it
}






float getArea(float l, float w)
{
  float area = l * w;
  return area;
}







String makeText(double temperature)
{
  String newText;
   if (temperature > 60.5)
   { 
    newText = "Very hot";
   }else{
    newText = "Not hot";
   }
   return newText;
}





double pi()
{

  double p = 3.141592;// 6 decimal points
  return p;// returns value of pi
}








float getPower(float i)
{
  return i*voltage;// 
}