3scope & Operators in Arduino
3scope & Operators in Arduino
Arduino
CSE- 315
Peripherals & Interfacing
Abdullah Al Omar
Lecturer, CSE, UAP
Scope
There are three types of scope in Arduino environment.
• Global Scope
• Formal Scope
• Local Scope
Global Scope: Global scope occurs when a variable is defined “outside of a function”.
1. the global scope is the scope that contains, and is visible in, all other scopes.
2. A variable with global scope has a lifetime that exists from the time the
program is loaded until the program terminates
Int T , S ;
float c = 0 ; Global variable declaration
void setup () {
//13 no. pin declaration
}
void loop(){
//13 no. pin ON/1
//13 no. pin OFF/0
}
Formal Scope:
Suppose int A() is a function:
int A( int x, int y){
int result;
result = x * y;
return result;
}
void setup(){
serial.begin(9600);
}
void loop() { Formal scope variable:
int i = 2;
int j = 3;
int k;
k = A(i, j); // k now contains 6
Serial.println(k);
delay(500);
}
Local Scope:
• The variable which resides in the function only. So the variable can only be
used in the function.
• These variables are not valid in outside of the function.
Void loop () {
int x , y ;
int z ; //Local variable declaration
x = 0;
y = 0; // initialization
z = 10;
}
Class Work (You have 10 minutes to complete the
task`)
Q1. Declare a variable containing your registration id, so that we can
use it in any block (any function). Assign it to the variable named
‘dhaka’ in the void loop function and pass it to a function to add 1 with
it. The function will return the value to the loop function.