SlideShare a Scribd company logo
Module – 4 IoT Physical Devices and End Point-Aurdino
Uno
1
Arduino:
οƒ˜ Arduino is an open-source electronics platform based on easy-
to-use hardware and software.
οƒ˜ Arduino boards are able to read inputs - light on a sensor, a
finger on a button, or a Twitter message - and turn it into an
output - activating a motor, turning on an LED, publishing
something online.
Module – 4 IoT Physical Devices and End Point-
Aurdino Uno
2
Arduino UNO:
οƒ˜ Arduino Uno is a microcontroller board based on the ATmega328P.
οƒ˜ It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP
header and a reset button.
οƒ˜ "Uno" means one in Italian and was chosen to mark the release of Arduino Software
(IDE) 1.0. The Uno board and version 1.0 of Arduino Software (IDE) were the
reference versions of Arduino, now evolved to newer releases.
Module – 4 IoT Physical Devices and End Point-
Aurdino Uno
3
1. Reset Button – This will restart any code that is loaded tothe
Arduino board
2. AREF – Stands for β€œAnalog Reference” and is used to set an
external reference voltage
3. Ground Pin – There are a few ground pins on the Arduinoand
they all work the same
analog output
4.Digital Input/Output – Pins 0-13 can be used for digital input or 12. 3.3V Pin – This pin supplies 3.3 volts of power to your projects
output
13. 5V Pin – This pin supplies 5 volts of power to your projects
5. PWM – The pins marked with the (~) symbol can simulate
6. USB Connection – Used for powering up your Arduino and
uploading sketches
7. TX/RX – Transmit and receive data indicationLEDs
8. ATmega Microcontroller – This is the brains and is where the
programs are stored
9. Power LED Indicator – This LED lights up anytime the board is
plugged in a power source
10. Voltage Regulator – This controls the amount of voltage going
into the Arduino board
11. DC Power Barrel Jack – This is used for poweringyour
Arduino with a power supply
14. Ground Pins – There are a few ground pins on theArduino
and they all work the same
15. Analog Pins – These pins can read the signal from an analog
sensor and convert it to digital
9
Module – 4 IoT Physical Devices and End Point-
Aurdino Uno
Module –4 IoT Physical Devices and End Point-Aurdino
Uno
Fundamentals of Arduino Programming:
Two required functions / methods / routines:
void setup()
{
// runs once
}
void loop()
{
// repeats
}
10
digitalWrite()
analogWrite()
digitalRead()
if() statements/ Boolean
analogRead()
Serialcommunication
BIG
6
CONCEPTS
Comments, Comments, Comments
Comments
// this is for single line comments
// it’s good to put at the top and before anything β€˜tricky’
/* this is for multi-line comments
Like this…
And this….
*/
comments
Three commands to know…
pinMode(pin, INPUT/OUTPUT);
ex: pinMode(13, OUTPUT);
digitalWrite(pin, HIGH/LOW);
ex: digitalWrite(13, HIGH);
delay(time_ms);
ex: delay(2500); // delay of 2.5 sec.
// NOTE: -> commands are CASE-sensitive
Arduino Code Basics
Arduino programs run on two basic sections:
void setup() {
//setup motors, sensors etc
}
void loop() {
// get information from sensors
// send commands to motors
}
SETUP
16 16
The setup section is used for assigning input and outputs
(Examples: motors, LED’s,sensors etc) to ports on theArduino
It also specifies whether the device is OUTPUT or INPUT
To do this we use the command β€œpinMode”
SETUP
void setup() {
pinMode(9, OUTPUT);
}
port #
Input or Output
void loop() {
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(1000);
}
L
OOP
Port # from setup
Turn the LED on
or off
Wait for 1 second
or 1000 milliseconds
13
int val = 5;
DECLARING A VARIABLE
Type
assignment
β€œbecomes”
variable name
value
14
USING VARIABLES
int delayTime = 2000;
digitalWrite(greenLED, HIGH);
delay(delayTime);
}
int greenLED = 9;
void setup() {
Declare delayTime
pinMode(greenLED, OUTPUT)V;ariable
}
void loop() {
Use delayTime
digitalWrite(greenLED, LOVWa)ri;able
delay(delayTime);
15
Using Variables
int delayTime = 2000;
int greenLED = 9;
}
void setup() {
pinMode(greenLED, OUTPUT);
}
void loop() {
digitalWrite(greenLED, HIGH);
delay(delayTime);
digitalWrite(greenLED, LOW);
delayTime = delayTime - 100;
delay(delayTime);
subtract 100 from
16
delayTime to gradually
increase LED’s blinking
speed
Conditions
To make decisions in Arduino code we
use an β€˜if’ statement
β€˜If’ statements are based on a TRUE or
FALSE question
23
VALUE COMPARISONS
GREATER THAN
a > b
LESS
a < b
EQUAL
a == b
GREATER THAN OR EQUAL
a >= b
LESS THAN OR EQUAL
a <= b
NOT EQUAL
a != b
IF Condition
if(true)
{
β€œperform some action”
}
25
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if(counter < 10)
{
Serial.println(counter);
}
counter = counter + 1;
}
IF Example
Input & Output
Transferring data from the computer to an Arduino
is done using Serial Transmission
To setup Serial communication we use the following
26
void setup() {
Serial.begin(9600);
}
21
Writing to the Console
void setup() {
Serial.begin(9600);
Serial.println(β€œHello World!”);
}
void loop() {}
22
IF - ELSE
Condition
if( β€œanswer is true”)
{
β€œperform some action”
}
else
{
β€œperform some other action”
}
29
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if(counter < 10)
{
Serial.println(β€œless than 10”);
}
else
{
Serial.println(β€œgreater than or equal to 10”);
Serial.end();
}
counter = counter + 1;}
IF - ELSE Example
IF - ELSE IF
Condition
if( β€œanswer is true”)
{
β€œperform some action”
}
else if( β€œanswer is true”)
{
β€œperform some other action”
}
31
int counter = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
if(counter < 10)
{
Serial.println(β€œless than 10”);
}
else if (counter == 10)
{
Serial.println(β€œequal to 10”);
}
else
{
Serial.println(β€œgreater than 10”);
Serial.end();
}
counter = counter + 1;
}
IF - ELSE Example
BOOLEAN OPERATORS - AND
27 32
If we want all of the conditions to be true we need to use β€˜AND’ logic (AND gate)
We use the symbols &&
β€’ Example
if ( val > 10 && val < 20)
BOOLEAN OPERATORS - OR
28
If we want either of the conditions to be true we need to use β€˜OR’ logic (OR gate)
We use the symbols ||
β€’ Example
if ( val < 10 || val > 20)
34
BOOLEAN VARIABLES
boolean done = true;
boolean done = false;
void setup() {
Serial.begin(9600);}
void loop() {
if(!done) {
Serial.println(β€œHELLOWORLD”);
done = true; }
}
Important functions
β€’ Serial.println(value);
– Prints the value to the Serial Monitor on your computer
β€’ pinMode(pin, mode);
– Configures a digital pin to read (input) or write (output) a digital value
β€’ digitalRead(pin);
– Reads a digital value (HIGH or LOW) on a pin set for input
β€’ digitalWrite(pin, value);
– Writes the digital value (HIGH or LOW) to a pin set for output
β€’ Essential Programming Concepts
– Delay
– Infinite Loop
β€’ General Input/Output
– Polling or Busy/Wait I/O
– Interrupt Processing
β€’ Timers and Internal Inteerrupts
β€’ High-Level Language Extensions
β€’ Code Transformations for Embedded Computing
– Loop Unrolling
– Loop Merging
– Loop Peeling
– Loop Tiling
OUTLINE
β€’ Delays are essential in embedded systems, unlike high-
performance systems where we want the program to
execute as fast as possible
β€’ Delays are used to synchronize events, or read inputs
with a specific sampling freqency (more on Bus/Wait I/O)
DELAY (1/3)
β€’ Okay, so how do we build a delay function?
β€’ Our reference is the system clock frequency
β€’ We use a register or a timer to measure ticks
β€’ Each tick is 1/frequency
β€’ Example: Assuming a 16-bit processor, an increment
and a jump instruction is 1-cycle each and a 10 MHz
system clock, build a 1-sec delay:
β€’ T = 1/10 MHz = 100 ns
β€’ 1 s/100 ns = 10,000,000
int i=5000000; //2 ticks per iteration
BACK: i--;
if (i!=0) goto BACK;
DELAY (3/3)
β€’ Embedded Systems are mostly single-functioned
β€’ Their core application never terminates
β€’ Infinite loops are not forbidden as long as they are done
correctly
Infinite Loop (1/2)
void main()
{
light enum {RED, ORANGE, GREEN};
loop: light = RED; //no exit from loop!
delay(20000); //20-sec red
light = ORANGE;
//2-sed orange
delay(2000);
light = GREEN;
delay(20000);
goto loop;
//20-sec green
//just repeat sequence
}
Infinite Loop (2/2)

More Related Content

PPT
Blue brain ppt
PPTX
Electronic Speed Control (ESC) Circuits, Working And Applications
PDF
WiFi 6 - Usher in the Era of Next-Generation Connectivity
PPT
Smart Dust
PPTX
WLAN(802.11AX - WI-FI 6) Evolution, frequency band, channels & use cases
PPTX
Seminar presentation on 5G
PPTX
5G wireless technology
PPTX
5G tecnology
Blue brain ppt
Electronic Speed Control (ESC) Circuits, Working And Applications
WiFi 6 - Usher in the Era of Next-Generation Connectivity
Smart Dust
WLAN(802.11AX - WI-FI 6) Evolution, frequency band, channels & use cases
Seminar presentation on 5G
5G wireless technology
5G tecnology

What's hot (20)

PPT
Powerpoint presentation on 5G wireless technology
PPTX
Sixth sense technology ppt
PDF
Diversity Techniques in Wireless Communication
PPTX
MIMO Calculation
PPTX
5G Wireless Technology
PPTX
RFID BASED ATTENDANCE SYSTEM.pptx
PPT
Presentation on 1G/2G/3G/4G/5G/Cellular & Wireless Technologies
PPTX
Pre-emphasis and de-emphasis circuits
PPT
4g wireless final ppt
Β 
PPTX
DIGITAL SIGNAL PROCESSING
PDF
IoT and Fingerprint Based Door Looking System
PPTX
5 g wireless system
PPTX
Non orthogonal multiple access
PDF
5G -NOMA & IBFD
PPTX
Wi-Fi Esp8266 nodemcu
PPTX
SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION
PPTX
Zigbee
PDF
Verilog full adder in dataflow & gate level modelling style.
DOCX
Beam forming- New Technology
PPT
WiMAX
Powerpoint presentation on 5G wireless technology
Sixth sense technology ppt
Diversity Techniques in Wireless Communication
MIMO Calculation
5G Wireless Technology
RFID BASED ATTENDANCE SYSTEM.pptx
Presentation on 1G/2G/3G/4G/5G/Cellular & Wireless Technologies
Pre-emphasis and de-emphasis circuits
4g wireless final ppt
Β 
DIGITAL SIGNAL PROCESSING
IoT and Fingerprint Based Door Looking System
5 g wireless system
Non orthogonal multiple access
5G -NOMA & IBFD
Wi-Fi Esp8266 nodemcu
SPACE DIVISION MULTIPLE ACCESS (SDMA) SATELLITE COMMUNICATION
Zigbee
Verilog full adder in dataflow & gate level modelling style.
Beam forming- New Technology
WiMAX
Ad

Similar to 4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf (20)

PDF
Syed IoT - module 5
PDF
ARUDINO UNO and RasberryPi with Python
PPTX
Introduction to Arduino Microcontroller
PPTX
Arduino board program for Mobile robotss
PDF
The IoT Academy IoT Training Arduino Part 3 programming
PPTX
Arduino Day 1 Presentation
PPTX
Arduino programming
PPTX
Arduino intro.pptx
PPT
Arduino_CSE ece ppt for working and principal of arduino.ppt
PDF
Arduino - Module 1.pdf
DOCX
Arduino and Circuits.docx
PPTX
Arduino cic3
PDF
Introduction of Arduino Uno
PDF
introductiontoarduino-111120102058-phpapp02.pdf
PPTX
Arduino Programming Familiarization
PDF
Arduino microcontroller ins and outs with pin diagram
PDF
Arduino-workshop.computer engineering.pdf
PDF
Arduino reference
PPTX
Ch_2_8,9,10.pptx
Syed IoT - module 5
ARUDINO UNO and RasberryPi with Python
Introduction to Arduino Microcontroller
Arduino board program for Mobile robotss
The IoT Academy IoT Training Arduino Part 3 programming
Arduino Day 1 Presentation
Arduino programming
Arduino intro.pptx
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino - Module 1.pdf
Arduino and Circuits.docx
Arduino cic3
Introduction of Arduino Uno
introductiontoarduino-111120102058-phpapp02.pdf
Arduino Programming Familiarization
Arduino microcontroller ins and outs with pin diagram
Arduino-workshop.computer engineering.pdf
Arduino reference
Ch_2_8,9,10.pptx
Ad

More from Jayanthi Kannan MK (10)

PPTX
1 18CS54 _Software Engineering and Testing _Introduction to CO PO _Syllabus ...
PDF
MODULE 1 Software Product and Process_ SW ENGG 22CSE141.pdf
PDF
2nd MODULE Software Requirements _ SW ENGG 22CSE141.pdf
PDF
Unit 2 Smart Objects _IOT by Dr.M.K.Jayanthi.pdf
PDF
5 IOT MODULE 5 RaspberryPi Programming using Python.pdf
PDF
3 IOT Part 3 IP as the IoT Network Layer Access Technologies.pdf
PDF
1 Unit 1 Introduction _IOT by Dr.M.K.Jayanthi Kannan (1).pdf
PDF
IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...
PDF
Introduction to Internet of Things
PPTX
ADBMS Object and Object Relational Databases
1 18CS54 _Software Engineering and Testing _Introduction to CO PO _Syllabus ...
MODULE 1 Software Product and Process_ SW ENGG 22CSE141.pdf
2nd MODULE Software Requirements _ SW ENGG 22CSE141.pdf
Unit 2 Smart Objects _IOT by Dr.M.K.Jayanthi.pdf
5 IOT MODULE 5 RaspberryPi Programming using Python.pdf
3 IOT Part 3 IP as the IoT Network Layer Access Technologies.pdf
1 Unit 1 Introduction _IOT by Dr.M.K.Jayanthi Kannan (1).pdf
IoT Arduino UNO, RaspberryPi with Python, RaspberryPi Programming using Pytho...
Introduction to Internet of Things
ADBMS Object and Object Relational Databases

Recently uploaded (20)

PPTX
Digital Literacy And Online Safety on internet
PDF
Testing WebRTC applications at scale.pdf
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
The Internet -By the Numbers, Sri Lanka Edition
Β 
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
artificial intelligence overview of it and more
DOCX
Unit-3 cyber security network security of internet system
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
Funds Management Learning Material for Beg
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
Digital Literacy And Online Safety on internet
Testing WebRTC applications at scale.pdf
Introuction about ICD -10 and ICD-11 PPT.pptx
SASE Traffic Flow - ZTNA Connector-1.pdf
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
international classification of diseases ICD-10 review PPT.pptx
The Internet -By the Numbers, Sri Lanka Edition
Β 
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
An introduction to the IFRS (ISSB) Stndards.pdf
Job_Card_System_Styled_lorem_ipsum_.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
artificial intelligence overview of it and more
Unit-3 cyber security network security of internet system
Tenda Login Guide: Access Your Router in 5 Easy Steps
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Funds Management Learning Material for Beg
SAP Ariba Sourcing PPT for learning material
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Β 
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
Cloud-Scale Log Monitoring _ Datadog.pdf

4 IOT 18ISDE712 MODULE 4 IoT Physical Devices and End Point-Aurdino Uno.pdf

  • 1. Module – 4 IoT Physical Devices and End Point-Aurdino Uno 1 Arduino: οƒ˜ Arduino is an open-source electronics platform based on easy- to-use hardware and software. οƒ˜ Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online.
  • 2. Module – 4 IoT Physical Devices and End Point- Aurdino Uno 2 Arduino UNO: οƒ˜ Arduino Uno is a microcontroller board based on the ATmega328P. οƒ˜ It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. οƒ˜ "Uno" means one in Italian and was chosen to mark the release of Arduino Software (IDE) 1.0. The Uno board and version 1.0 of Arduino Software (IDE) were the reference versions of Arduino, now evolved to newer releases.
  • 3. Module – 4 IoT Physical Devices and End Point- Aurdino Uno 3
  • 4. 1. Reset Button – This will restart any code that is loaded tothe Arduino board 2. AREF – Stands for β€œAnalog Reference” and is used to set an external reference voltage 3. Ground Pin – There are a few ground pins on the Arduinoand they all work the same analog output 4.Digital Input/Output – Pins 0-13 can be used for digital input or 12. 3.3V Pin – This pin supplies 3.3 volts of power to your projects output 13. 5V Pin – This pin supplies 5 volts of power to your projects 5. PWM – The pins marked with the (~) symbol can simulate 6. USB Connection – Used for powering up your Arduino and uploading sketches 7. TX/RX – Transmit and receive data indicationLEDs 8. ATmega Microcontroller – This is the brains and is where the programs are stored 9. Power LED Indicator – This LED lights up anytime the board is plugged in a power source 10. Voltage Regulator – This controls the amount of voltage going into the Arduino board 11. DC Power Barrel Jack – This is used for poweringyour Arduino with a power supply 14. Ground Pins – There are a few ground pins on theArduino and they all work the same 15. Analog Pins – These pins can read the signal from an analog sensor and convert it to digital 9 Module – 4 IoT Physical Devices and End Point- Aurdino Uno
  • 5. Module –4 IoT Physical Devices and End Point-Aurdino Uno Fundamentals of Arduino Programming: Two required functions / methods / routines: void setup() { // runs once } void loop() { // repeats } 10
  • 7. Comments, Comments, Comments Comments // this is for single line comments // it’s good to put at the top and before anything β€˜tricky’ /* this is for multi-line comments Like this… And this…. */
  • 9. Three commands to know… pinMode(pin, INPUT/OUTPUT); ex: pinMode(13, OUTPUT); digitalWrite(pin, HIGH/LOW); ex: digitalWrite(13, HIGH); delay(time_ms); ex: delay(2500); // delay of 2.5 sec. // NOTE: -> commands are CASE-sensitive
  • 10. Arduino Code Basics Arduino programs run on two basic sections: void setup() { //setup motors, sensors etc } void loop() { // get information from sensors // send commands to motors }
  • 11. SETUP 16 16 The setup section is used for assigning input and outputs (Examples: motors, LED’s,sensors etc) to ports on theArduino It also specifies whether the device is OUTPUT or INPUT To do this we use the command β€œpinMode”
  • 12. SETUP void setup() { pinMode(9, OUTPUT); } port # Input or Output
  • 13. void loop() { digitalWrite(9, HIGH); delay(1000); digitalWrite(9, LOW); delay(1000); } L OOP Port # from setup Turn the LED on or off Wait for 1 second or 1000 milliseconds 13
  • 14. int val = 5; DECLARING A VARIABLE Type assignment β€œbecomes” variable name value 14
  • 15. USING VARIABLES int delayTime = 2000; digitalWrite(greenLED, HIGH); delay(delayTime); } int greenLED = 9; void setup() { Declare delayTime pinMode(greenLED, OUTPUT)V;ariable } void loop() { Use delayTime digitalWrite(greenLED, LOVWa)ri;able delay(delayTime); 15
  • 16. Using Variables int delayTime = 2000; int greenLED = 9; } void setup() { pinMode(greenLED, OUTPUT); } void loop() { digitalWrite(greenLED, HIGH); delay(delayTime); digitalWrite(greenLED, LOW); delayTime = delayTime - 100; delay(delayTime); subtract 100 from 16 delayTime to gradually increase LED’s blinking speed
  • 17. Conditions To make decisions in Arduino code we use an β€˜if’ statement β€˜If’ statements are based on a TRUE or FALSE question
  • 18. 23 VALUE COMPARISONS GREATER THAN a > b LESS a < b EQUAL a == b GREATER THAN OR EQUAL a >= b LESS THAN OR EQUAL a <= b NOT EQUAL a != b
  • 20. 25 int counter = 0; void setup() { Serial.begin(9600); } void loop() { if(counter < 10) { Serial.println(counter); } counter = counter + 1; } IF Example
  • 21. Input & Output Transferring data from the computer to an Arduino is done using Serial Transmission To setup Serial communication we use the following 26 void setup() { Serial.begin(9600); } 21
  • 22. Writing to the Console void setup() { Serial.begin(9600); Serial.println(β€œHello World!”); } void loop() {} 22
  • 23. IF - ELSE Condition if( β€œanswer is true”) { β€œperform some action” } else { β€œperform some other action” }
  • 24. 29 int counter = 0; void setup() { Serial.begin(9600); } void loop() { if(counter < 10) { Serial.println(β€œless than 10”); } else { Serial.println(β€œgreater than or equal to 10”); Serial.end(); } counter = counter + 1;} IF - ELSE Example
  • 25. IF - ELSE IF Condition if( β€œanswer is true”) { β€œperform some action” } else if( β€œanswer is true”) { β€œperform some other action” }
  • 26. 31 int counter = 0; void setup() { Serial.begin(9600); } void loop() { if(counter < 10) { Serial.println(β€œless than 10”); } else if (counter == 10) { Serial.println(β€œequal to 10”); } else { Serial.println(β€œgreater than 10”); Serial.end(); } counter = counter + 1; } IF - ELSE Example
  • 27. BOOLEAN OPERATORS - AND 27 32 If we want all of the conditions to be true we need to use β€˜AND’ logic (AND gate) We use the symbols && β€’ Example if ( val > 10 && val < 20)
  • 28. BOOLEAN OPERATORS - OR 28 If we want either of the conditions to be true we need to use β€˜OR’ logic (OR gate) We use the symbols || β€’ Example if ( val < 10 || val > 20)
  • 29. 34 BOOLEAN VARIABLES boolean done = true; boolean done = false; void setup() { Serial.begin(9600);} void loop() { if(!done) { Serial.println(β€œHELLOWORLD”); done = true; } }
  • 30. Important functions β€’ Serial.println(value); – Prints the value to the Serial Monitor on your computer β€’ pinMode(pin, mode); – Configures a digital pin to read (input) or write (output) a digital value β€’ digitalRead(pin); – Reads a digital value (HIGH or LOW) on a pin set for input β€’ digitalWrite(pin, value); – Writes the digital value (HIGH or LOW) to a pin set for output
  • 31. β€’ Essential Programming Concepts – Delay – Infinite Loop β€’ General Input/Output – Polling or Busy/Wait I/O – Interrupt Processing β€’ Timers and Internal Inteerrupts β€’ High-Level Language Extensions β€’ Code Transformations for Embedded Computing – Loop Unrolling – Loop Merging – Loop Peeling – Loop Tiling OUTLINE
  • 32. β€’ Delays are essential in embedded systems, unlike high- performance systems where we want the program to execute as fast as possible β€’ Delays are used to synchronize events, or read inputs with a specific sampling freqency (more on Bus/Wait I/O) DELAY (1/3)
  • 33. β€’ Okay, so how do we build a delay function? β€’ Our reference is the system clock frequency β€’ We use a register or a timer to measure ticks β€’ Each tick is 1/frequency β€’ Example: Assuming a 16-bit processor, an increment and a jump instruction is 1-cycle each and a 10 MHz system clock, build a 1-sec delay: β€’ T = 1/10 MHz = 100 ns β€’ 1 s/100 ns = 10,000,000 int i=5000000; //2 ticks per iteration BACK: i--; if (i!=0) goto BACK; DELAY (3/3)
  • 34. β€’ Embedded Systems are mostly single-functioned β€’ Their core application never terminates β€’ Infinite loops are not forbidden as long as they are done correctly Infinite Loop (1/2)
  • 35. void main() { light enum {RED, ORANGE, GREEN}; loop: light = RED; //no exit from loop! delay(20000); //20-sec red light = ORANGE; //2-sed orange delay(2000); light = GREEN; delay(20000); goto loop; //20-sec green //just repeat sequence } Infinite Loop (2/2)