Module-5 Smart and Connected Cities
Module-5 Smart and Connected Cities
Module-5 Smart and Connected Cities
void setup() {
pinMode(12, OUTPUT); // set the pin mode
}
void loop() {
digitalWrite(12, HIGH); // Turn on the LED
delay(1000);
digitalWrite(12, LOW); //Turn of the LED
delay(1000); }
• Set the pin mode as output which is connected to the
led, pin 12 in this case.
• Use digitalWrite() function to set the output as HIGH
and LOW
• Delay() function is used to specify the delay between
HIGH-LOW transition of the output
Operators
• Arithmetic Operators: =, +, -, *, /, %
• Comparison Operator: ==, !=, <, >, <=, >=
• Boolean Operator: &&, ||, !
• Bitwise Operator: &, |, ^, ~, <<, >>,
• Compound Operator: ++, --, +=, -=, *=, /=, %=, |=,
&=
• Control Statement
If statement if(condition){
Statements if the
condition is true ;
}
If…Else statement if(condition ){
Statements if the
condition is true;
}
else{
Statements if the
condition is false;
}
• If…….Elseif…..Else
if (condition1)
{
Statements if the condition1 is true;
}
else if (condition2)
{ Statements if the condition1 is false and
condition2 is true;
} else{ Statements if both the conditions are
false; }
• Switch Case Switch(choice)
{ case opt1: statement_1;break;
case opt2: statement_2;break;
case opt3: statement_3;break;
...
case default: statement_default; break;
} Conditional Operator. Val=(condition)?
(Statement1): (Statement2)
• Loops
For loop
for(initialization; condition; increment){
Statement till the condition is true;
}
While loop
while(condition){
Statement till the condition is true;
}
Do… While loop
Do{
Statement till the condition is true;
}while(condition);
Arrays
• Collection of elements having homogenous
datatypethat are stored in adjacent memory location.
The conventional starting index is 0.
Declaration of array: <Datatype> array_name[size];
Ex: intarre[5];
Alternative Declaration:
int arre[]={0,1,2,3,4};
int arre[5]={0,1,2};
Multi-dimentional array Declaration:
<Datatype> array_name[n1] [n2][n3]….;
Ex: int arre[row][col][height];
String
Array of characters with NULL as termination is
termed as a String.
Declaration using Array: char str[]=“ABCD”; char
str[4]; str[0]=‘A’; str[0]=‘B’; str[0]=‘C’; str[0]=0;
Declaration using String Object: String str=“ABC”;
str.ToUpperCase(): change all the characters of str to
upper case
str.replace(str1,str2): is str1 is the sub string of str then
it will be replaced by str2
str.length(): returns the length of the string without
considering null
Math Library
• To apply the math functions and mathematical constants,
“MATH.h” header files is needed to be included.
Functions: cos(double radian); sin(double radian); tan(double
radian); fabs(double val); fmod(double val1, double val2);
exp(double val); log(double val); log10(double val);
square(double val); pow(double base, double power);
• Random Number
randomSeed(intv): reset the pseudo-random number generator
with seed value v
• random(maxi)=gives a random number within the range
[0,maxi]
• random(mini,maxi)=gives a random number within the
range [mini,maxi]
Interrupts
• An external signal for which system blocks the
current running process to process that signal
Types: Hardware interrupt
Software interrupt
• digitalPinToInterrupt(pin):
• Change actual digital pin to the specific
interrupt
number.attachInterrupt(digitalPinToInterrupt(
pin),ISR, mode);
• ISR: a interrupt service routine have to be defined