0% found this document useful (0 votes)
18 views39 pages

Class 06 - REC-Basic Robotics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views39 pages

Class 06 - REC-Basic Robotics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Basic 𝐑𝐨𝐛𝐨𝐭𝐢𝐜𝐬

– Robotics Engineering Certification

Let’s Start the Robotics Journey


Class 06-

Arduino Programming- 5
Function
What is a
Function?
What is a Function?

INPUT OUTPUT
PROCESS
Function in Mathematics

f(x) = 2x-1
Function in Mathematics

f(x) = 2x-1

Function Name
Function in Mathematics

f(x) = 2x-1

Function Name

Function
Description
Function in Mathematics

Function
f(x) = 2x-1

Function Name

Function
Description
Function in Mathematics

x=
f(x) = 2x-1 1,2,3,4,....
Function in Mathematics

f(x) = 2x-1
Function in Mathematics

x=
f(x) = 2x-1 1,2,3,4,....

f(x)=1,3,5,..
.
Function in Mathematics

INPUT
x=
f(x) = 2x-1 1,2,3,4,....

f(x)=1,3,5,..
.
Function in Mathematics

INPUT
x=
OUTPU
T f(x) = 2x-1 1,2,3,4,....

f(x)=1,3,5,..
.
Function in Mathematics

f(x) = 2x-1
OUTPU f(INPUT) = (Function Description)
T
Function in Mathematics

OUTPU f(INPUT) = (Function Description)


T
Function in Mathematics

OUTPU f(INPUT) = (Function Description)


T
OUTPU g(INPUT) = (Function Description)
T
Function in Mathematics

OUTPU f(INPUT) = (Function Description)


T
OUTPU g(INPUT) = (Function Description)
T
OUTPU a(INPUT) = (Function Description)
T
Function in Mathematics

OUTPU f(INPUT) = (Function Description)


T
OUTPU g(INPUT) = (Function Description)
T
OUTPU a(INPUT) = (Function Description)
T
OUTPUT functionName(INPUT) = (Function Description)
Function in Mathematics

f(x,y) = 2x+y-1
Function in Mathematics

f(x,y) = 2x+y-1
functionName(Input_1,Input_2) =
OUTPUT
(Function Description)
Function in
Programming:
Function in Programming:

functionName(Input_1,Input_2) =
OUTPUT
(Function Description)
Function in Programming:

functionName(Input_1,Input_2) =
OUTPUT
(Function Description)

OUTPUT_TYPE functionName(Input_1,Input_2)
{
Function Description
}
Function in Programming:
OUTPUT_TYPE functionName(Input_1,Input_2)
{
Function Description
}

returnType functionName(parameters)
{
// Code block
return value;
}
Built In functions of Arduino:

void setup() {
// Executes only one time
//Codes
}

void loop() {
// Executes Repeatedly
//Codes
}
Creating Custom function:

int sumTwo( int number1,int number2 ){


int sum=number1 + number2;
return sum;
}
Function Call:

void setup() {
Serial.print(9600);
}

void loop() {
int sum = sumTwo(3,5); //Calling Function
Serial.println(sum);
}
Types of Function:
1. Function without returnType and Parameters
2. Function without returnType
3. Function with returnType and parameters
Types of Function:
Function without returnType and Parameters
void sumTwo(){
Seria.print(“Function without returnType and Parameters”);
}
Types of Function:
Function without returnType
void sumTwo(int a, int b){
Seria.print(a+b);
}
Types of Function:
Function with returnType and parameters

int sumTwo( int number1,int number2 ){


int sum=number1 + number2;
return sum;
}
void setup()
{
Serial.begin(9600);
printNumbers(10,12);
}

void loop()
{

int sumTwo(int number1, int number2)


{
int sum=number1+number2;
return sum;
}

void printHello(){
Serial.println("Hello");
}

void printNumbers(int n1,int n2){


Serial.println(sumTwo(5,3));
Serial.println(sumTwo(10,-2));
printHello();
Serial.println(n1);
Serial.println(n2);
}
int led_pin=6;
int led_pin2=13;
void setup()
{
pinMode(led_pin,OUTPUT);
pinMode(led_pin2,OUTPUT);
}

void loop()
{
blinkLed(led_pin);
blinkLed(led_pin2);
}

void blinkLed(int pin_no){


digitalWrite(pin_no,HIGH);
delay(200);
digitalWrite(pin_no,LOW);
delay(200);
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(buttonValue(7)==1){
ledOn(8);
}
else{
ledOff(8);
}
}
bool buttonValue(int button_pin){
pinMode(button_pin,INPUT);
return digitalRead(button_pin);
}
void ledOn(int led_pin){
pinMode(led_pin,OUTPUT);
digitalWrite(led_pin,HIGH);
}
void ledOff(int led_pin){
pinMode(led_pin,OUTPUT);
digitalWrite(led_pin,LOW);
}
QnA
Exercise

You might also like