SlideShare a Scribd company logo
1 of 16
STREAM:
CIRCUITS AND IOT WITH ARDUINO
THINK-PAIR-SHARE
B
Arrays
 An array is a collection of variables with the same data types. It is a very
useful enhancement to variables that allows a single variable name to
store multiple values. To access the stored information inside an array,
the location of the data needs to be specified when using an array. This
location is also known as the Index of the array and the stored
information inside the array is called Elements. The index of an array
always starts the counting from Zero.
Array
 • int – is a variable data type that can store whole numbers.
• ledPin - is the variable name. This follows the rules when naming
variables.
• [ ] Square Brackets - After the variable name, a set of square brackets
must be put with a number inside of it. This number represents the size
of the array, also known as the number of "Elements” inside an
array.
 ; semicolon - A semicolon is placed after the square brackets to indicate
the end of the statement.
Array
With this example, we have 5 elements that can store integer information. If
we want to access the first element, we need to call index zero. Just like this:
ledPin [0]
Since the index starts at zero and we only have 5 elements inside the array,
we can say:
Array
If we want to store information in every element, we can
declare in the parameter:
ledPin [0]
ledPin [1]
ledPin [2]
ledPin [3]
ledPin [4]
Similar to a regular variable, an array must be declared
before it can be used.
How do we initialize an array?
 When an array is used in a function, typically it is not assigned yet will
values. With this, we can call the index of the array and store
information, just like the example given above. In other cases, arrays
can be explicitly given values. These values need to be inside a set of
curly braces after an equal symbol.
 For example:
int ledPin [5] = {2, 3, 4, 5, 8};
This line of code is similar to:
How do we initialize an array?
 Where:
 • = Equal symbol - is used to assign values to an array.
 • { } Curly Braces - The elements of an array need to be stored inside a
set of curly braces to define the start and end of a code block.
 • , Comma - The elements inside an array needs to be separated with a
comma. In C and C++, commas are used as a separator of definitions
and function calls.
How do we initialize an array?
 With this example, we have 5 elements that can store integer
information. If we want to access the second element, we need to call
index one. Just like this:
ledPin [1]
 With the evolution of C++, it has led to the adoption of universal
initialization also for arrays. An equal sign can no longer be used
between the declaration and the initialized values. The following
examples are similar:
 int ledPin [5] = {2, 3, 4, 5, 8};
Accessing the Values in an Array
How can we access the values stored in an Array?
The values inside an array can be accessed similar to
how the values of regular variables are accessed with the
same data type.
For example:
int ledPin [5];
Just like our example previously, this is similar to:
Accessing the Values in an Array
If we want to store integer information in Index 1, we can
do it like this:
ledPin [1] = 3;
An array with a specified index that was previously stored
with information, can be used also to assign values to other
declared values.
For example,
ledPin [1] = 3;
Array Programming Example
Circuit Diagram
Array Programming Example
For the code, copy the program shown below. It will light up the LED lights, and it
will explain further the use of arrays in programming.
 int ledPins [5] = {3,5,6,9};
 void setup()
 {
 pinMode (ledPins [0],OUTPUT);
 pinMode (ledPins [1],OUTPUT);
 pinMode (ledPins [2],OUTPUT);
 pinMode (ledPins [3],OUTPUT);
 }
Array Programming Example
 void loop ()
 {
 analogWrite (ledPins [0],HIGH);
 analogWrite (ledPins [1],HIGH);
 analogWrite (ledPins [2],HIGH);
 analogWrite (ledPins [3],HIGH);
 delay (1000);
 }
TRANSFER
 Using the Diagram below create a program using array function
which will make the led turn ON with 1 second ( 1000) delay and
upload it in the arduino to test the program.
Assignment:
 On a short coupon bond, using the diagram provided, write a the
appropriate program using array function putting the led ON with a 1000
(1 second) delay and OFF with a 2000 (2 seconds) delay. Present to the
class tomorrow.

More Related Content

Similar to DEMO.ppt

Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
dfsdg3
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 

Similar to DEMO.ppt (20)

ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
ppt on arrays in c programming language.pptx
ppt on arrays in c programming language.pptxppt on arrays in c programming language.pptx
ppt on arrays in c programming language.pptx
 
Arrays accessing using for loops
Arrays accessing using for loopsArrays accessing using for loops
Arrays accessing using for loops
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Arrays.pptx
 Arrays.pptx Arrays.pptx
Arrays.pptx
 
Pandas csv
Pandas csvPandas csv
Pandas csv
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
c++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptxc++ arrays and pointers grade 9 STEP curriculum.pptx
c++ arrays and pointers grade 9 STEP curriculum.pptx
 
Cunit3.pdf
Cunit3.pdfCunit3.pdf
Cunit3.pdf
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
12000121037.pdf
12000121037.pdf12000121037.pdf
12000121037.pdf
 
Unit ii data structure-converted
Unit  ii data structure-convertedUnit  ii data structure-converted
Unit ii data structure-converted
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
java.pdf
java.pdfjava.pdf
java.pdf
 
Arrays in c v1 09102017
Arrays in c v1 09102017Arrays in c v1 09102017
Arrays in c v1 09102017
 
Arraysincv109102017 180831194256
Arraysincv109102017 180831194256Arraysincv109102017 180831194256
Arraysincv109102017 180831194256
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
unit1Intro_final.pptx
unit1Intro_final.pptxunit1Intro_final.pptx
unit1Intro_final.pptx
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 

Recently uploaded

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

DEMO.ppt

  • 3. Arrays  An array is a collection of variables with the same data types. It is a very useful enhancement to variables that allows a single variable name to store multiple values. To access the stored information inside an array, the location of the data needs to be specified when using an array. This location is also known as the Index of the array and the stored information inside the array is called Elements. The index of an array always starts the counting from Zero.
  • 4. Array  • int – is a variable data type that can store whole numbers. • ledPin - is the variable name. This follows the rules when naming variables. • [ ] Square Brackets - After the variable name, a set of square brackets must be put with a number inside of it. This number represents the size of the array, also known as the number of "Elements” inside an array.  ; semicolon - A semicolon is placed after the square brackets to indicate the end of the statement.
  • 5. Array With this example, we have 5 elements that can store integer information. If we want to access the first element, we need to call index zero. Just like this: ledPin [0] Since the index starts at zero and we only have 5 elements inside the array, we can say:
  • 6. Array If we want to store information in every element, we can declare in the parameter: ledPin [0] ledPin [1] ledPin [2] ledPin [3] ledPin [4] Similar to a regular variable, an array must be declared before it can be used.
  • 7. How do we initialize an array?  When an array is used in a function, typically it is not assigned yet will values. With this, we can call the index of the array and store information, just like the example given above. In other cases, arrays can be explicitly given values. These values need to be inside a set of curly braces after an equal symbol.  For example: int ledPin [5] = {2, 3, 4, 5, 8}; This line of code is similar to:
  • 8. How do we initialize an array?  Where:  • = Equal symbol - is used to assign values to an array.  • { } Curly Braces - The elements of an array need to be stored inside a set of curly braces to define the start and end of a code block.  • , Comma - The elements inside an array needs to be separated with a comma. In C and C++, commas are used as a separator of definitions and function calls.
  • 9. How do we initialize an array?  With this example, we have 5 elements that can store integer information. If we want to access the second element, we need to call index one. Just like this: ledPin [1]  With the evolution of C++, it has led to the adoption of universal initialization also for arrays. An equal sign can no longer be used between the declaration and the initialized values. The following examples are similar:  int ledPin [5] = {2, 3, 4, 5, 8};
  • 10. Accessing the Values in an Array How can we access the values stored in an Array? The values inside an array can be accessed similar to how the values of regular variables are accessed with the same data type. For example: int ledPin [5]; Just like our example previously, this is similar to:
  • 11. Accessing the Values in an Array If we want to store integer information in Index 1, we can do it like this: ledPin [1] = 3; An array with a specified index that was previously stored with information, can be used also to assign values to other declared values. For example, ledPin [1] = 3;
  • 13. Array Programming Example For the code, copy the program shown below. It will light up the LED lights, and it will explain further the use of arrays in programming.  int ledPins [5] = {3,5,6,9};  void setup()  {  pinMode (ledPins [0],OUTPUT);  pinMode (ledPins [1],OUTPUT);  pinMode (ledPins [2],OUTPUT);  pinMode (ledPins [3],OUTPUT);  }
  • 14. Array Programming Example  void loop ()  {  analogWrite (ledPins [0],HIGH);  analogWrite (ledPins [1],HIGH);  analogWrite (ledPins [2],HIGH);  analogWrite (ledPins [3],HIGH);  delay (1000);  }
  • 15. TRANSFER  Using the Diagram below create a program using array function which will make the led turn ON with 1 second ( 1000) delay and upload it in the arduino to test the program.
  • 16. Assignment:  On a short coupon bond, using the diagram provided, write a the appropriate program using array function putting the led ON with a 1000 (1 second) delay and OFF with a 2000 (2 seconds) delay. Present to the class tomorrow.