0% found this document useful (0 votes)
4 views

Arduino Statements

The document outlines the principles of control interfaces, including control statements in Arduino programming such as conditional and iterative statements. It explains how to use if, switch, for, while, and do-while statements to control program flow and execute code based on conditions. Additionally, it covers the integration of status indicators into control interfaces.

Uploaded by

waffiewaffle130
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Arduino Statements

The document outlines the principles of control interfaces, including control statements in Arduino programming such as conditional and iterative statements. It explains how to use if, switch, for, while, and do-while statements to control program flow and execute code based on conditions. Additionally, it covers the integration of status indicators into control interfaces.

Uploaded by

waffiewaffle130
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Objectives:

 Discuss the principles and concepts of


control interface, functions, status
indicator devices, actuator and
locomotion. (SSP_TLE-CT10FEI-IIIa-
1.1)
 Integrate status indicator to control
interface. (SSP_TLE-CT10FEI-IIIb-c1.2)
ARDUINO
STATEMENTS
Control Statements
 Program Flow- the order or
direction in which code is
executed
 Flow Control- the ability to alter
this order of executing commands
2 Kinds of statements:
1. Conditional Statements- that
includes the if and switch statements
selectively perform certain actions based on
the state of condition.
2. Iterative Statements- that includes the
for and while statements are often called
loops because of loop() function, they’ll loop
to the beginning of the statement and repeat
their code when condition has been met.
 While statement and while loop- is used to
continuously execute a statement so long as
the condition remains true.

While (condition)
{
statements;
}
Switch
 Switch statement is like a really nifty version of
the if statement in that it can execute one or
more blocks of code, depending on a range of
conditions.
 This basically a statement that compares the
value of an expression against a list of cases
executing whatever code begins after that case
when a match is found.
Switch (expression)
{
case constant;
statements;
case constant;
statements;
default;
statements;
}
 This can be used inside other control
Break statements to immediately end the loop or
statements.

For (int i=0; i<5; i++)


{
if (digitalRead(2)== HIGH) break;
digitalWrite (13, HIGH);
delay(250);
digitalWrite(13,LOW);
delay(250);
}
Continue For (int i=9; i<=13; i++)
 Does not exist or quit {
an iterative loop like if (I % 2== 0) continue;
break does, but rather
it skips over any digitalWrite (i, HIGH);
remaining statements delay(500);
inside the loop and
goes on the next digitalWrite(i,LOW);
repetition of the loop. delay(500);
}
Conditional codes/
statements
ARDUINO CODES
If Statement If (someVariable ??
 Test whether a certain
condition has been reached, Value)
such as an analog value
being above a certain {
number, and execute any
statements inside the doSomething;
brackets if the statement is
true. }
 If false the program skips
over the statement.
Note!
= is meant by this… x=10 X
equals 10

== is meant by this x==10 X


is equals to 10
If… else If (inputPin == HIGH)
{
 Allows for “either-
doThingA;
or” decisions to be
made. }
else
{
doThingB;
}

If… else If (inputPin < 500)
Else can also precede
{
another if test, so that
doThingA;
multiple, mutually exclusive
}
tests can be run at the
same time. Else if (inputPin >= 1000)
 {
It is even possible to have
doTHingB;
an unlimited number of
}
these else branches.
Else
 Remember though, only {
one set of statement will be
doThingC;
run depending on the
}
condition tests.
for Statement for (initialization;
 Is used to repeat a block of
statements enclosed in curly condition;
braces a specified number of
times. expression)
 An increment counter is often
used to increment and {
terminate the loop.
 There are three parts, doSomething;
separated by semicolons (;), to
the for loop header. }
for Statement
for (int i=0; i<20; i++) //declares I, tests if less
{ //than 20, increments I by 1
digitalWrite (13, HIGH); //turns pin 13 on
delay (250); //pauses for ¼ second
digitalWrite (13, LOW) //turns pin 13 off
delay (250); //pauses for ¼ second
}
while loop
 This loops continually and while
infinitely until all expression
inside the parenthesis (someVariable ??
becomes false.
 Something must change the
Value)
tested variable, or the while
loop will never exit.
{
 This could be in your code,
such as an incremented
doSomething;
variable, or an external
condition, such as testing a }
sensor.
while loop
while(someVariable < 200) //test if less than 200
{
doSomething; //executes enclosed statements
someVariable++; //increments variable by 1
}
Do…while Do
 The do loop is a bottom
driven loop that works in the {
same manner as the while
loop, with the exception that
the condition is tested at the
doSomething;
end of the loop, so the do
loop will always run at the } while
least once.
(someVariable ??
value);
Do…while
do
{
x = readSensors(); //assigns the value of
//readSensors () to x
delay (50); //pauses 50 milliseconds
} while (x < 100); //loops if x is less than 100

You might also like