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

AMC Reference Sheet

This document provides definitions for key terminology used in an Arduino mini-course, including duty cycle, frequency, pin, period, power, PWM, signal, variable types (integer, floating point, boolean), and conditional statements (if, else, else if) and loops (for). It explains concepts like local vs global variables, boolean and comparison operators for conditional logic, and examples of if, else, and else if statements.

Uploaded by

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

AMC Reference Sheet

This document provides definitions for key terminology used in an Arduino mini-course, including duty cycle, frequency, pin, period, power, PWM, signal, variable types (integer, floating point, boolean), and conditional statements (if, else, else if) and loops (for). It explains concepts like local vs global variables, boolean and comparison operators for conditional logic, and examples of if, else, and else if statements.

Uploaded by

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

COURSE REFERENCE MATERIAL

KEY TERMINOLOGY

Listed below are the key terms covered in this mini-course with their respective
definitions.

● Duty Cycle: The fraction of one period in which a signal is active. Measured as
a percentage of the period.

● Frequency: How often an event repeats per unit time (e.g. the number of times
a signal’s waveform repeats itself per second).

● IDE: Integrated Development Environment. Software that provides tools to


users for building applications.

● LED: Light Emitting Diode. A semiconductor that emits light when current flows
through it. The on-board LED of the Arduino is connected to Pin13 and is used
in the “Blinky” example.

● Pin: A type of electrical contact used to connect circuit components. The digital
pins on the Arduino can be configured to either read or write signals by setting
them to be input pins or output pins. The Arduino Uno has 14 digital pins as well
as 6 analog input pins.

● Period: The amount of time for one cycle of something to complete (e.g. time
in seconds it takes for a signal’s waveform to repeat itself). The reciprocal of
the frequency.

● Power: The rate per unit time that electrical energy is transferred in a circuit.
Measured in watts.

o AC Power: Alternating Current. Current in AC power alternates between


a positive high and an equal but negative low in the form of a sinusoidal
wave.

o DC Power: Direct Current. Current in DC power is linear – it remains


static and moves in a straight line when viewed on an x-y plot.

● PWM: Pulse Width Modulation. A method used to simulate analog signals with
digital signal outputs. The width of the signal's pulse is changed, or modulated,
such that the average output voltage is the same as the desired analog
© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved
voltage. PWM has two key characteristics that determine its behaviour: duty
cycle and frequency.

● Serial Communication: The process of sending data via digital signals one bit
at a time.

● Signal: An electric current used to convey data/information from one place to


another.

o Analog Signal: A continuous signal that can hold any value between
ground and its supply voltage. In this way an electrical signal represents
data/information analogously to another time-varying signal.

o Digital Signal: A discrete signal that represents data/information with a


sequence of high and low values. The high values correspond to a
Boolean true/binary 1, while the low values correspond to a Boolean
false/binary 0.

© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved


VARIABLES

A variable is a storage location that is identified by a symbolic name. Example types


of information stored in variables include data read from sensors, text inputs from
users, intermediate values used in calculations and much more.

Variables can have different types depending on their intended purpose. There are
three key data types you will need to know before starting the course.

Integer
Integers store only discrete integer values ranging from -32,768 to 32,767 (e.g. -1, 8,
378, -47, etc.).

To declare a variable as an integer, use the following syntax:

int myNumber = 7;
The above code declares an integer (int) named myNumber and sets its stored value
to 7.

For more information, please see the official Arduino documentation:

https://www.arduino.cc/reference/en/language/variables/data-types/int/

Floating Point Number


A floating point number, commonly known as a float, stores real numbers (i.e.
numbers that can have a decimal point). Floats can store values ranging from
3.4028235E+38 to 3.4028235E+38.

To declare a variable as a float, use the following syntax:

float myNumber = 78.36;


The above code declares a float named myNumber and sets its stored value to 78.36.

For more information, please see the official Arduino documentation:

https://www.arduino.cc/reference/en/language/variables/data-types/float/

© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved


Boolean
A Boolean variable can store only two values: true or false. Boolean values are useful
for conditional statements where certain code should only be executed if a certain
condition is either true or false.

To declare a variable as a Boolean, use the following syntax:

bool myBool = true;


The above code declares a Boolean named myBool and sets its stored value to true.

For more information, please see the official Arduino documentation:

https://www.arduino.cc/reference/en/language/variables/data-types/bool/

Local and Global Variables


Variables can only be used within the scope that they are declared. For example, a
variable defined inside of a function cannot be accessed or used inside of another
function. This is what is known as a “local” variable. A global variable, on the other
hand, is a variable declared outside the scope of a function and can be used
anywhere.

// This is a global variable and can be accessed anywhere in the program


int myGlobalVariable = 7;

void loop() {
// This is a local variable and can only be accessed within thisloop()
// function
int myLocalVariable = 6;
}

© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved


BOOLEAN OPERATORS

A conditional is something that is used to specify that a block of code should be


executed only if certain conditions are met. There are three types of conditionals that
you will need to know for the completion of this course, “if”, “else” and “else if”.

Boolean and comparison operators are used to create the Boolean conditions for a
conditional statement. Logical operations follow order of operations. Parentheses can
be used to specify that one logical operation should be performed before another.

Boolean operators use Boolean operands (i.e. ‘true’ or ‘false’) and they are listed in
the following table:

Boolean Operation Symbol Description


NOT !x Will return true if x is false and vice versa.
AND x && y Will return true if operands x and y are both true.
OR x || y Will return true if either x or y is true.

Comparison operators use numerical operands and are listed in the following table:

Comparison Operation Symbol Description


EQUALS x == y Will return true if x is exactly equal to y
NOT EQUALS x != y Will return true if x is not equal to y
GREATER THAN x > y Will return true if x is greater than y
LESS THAN x < y Will return true if x is less than y
GREATER THAN OR EQUAL x >= y Will return true if x is greater than or equal to y
TO
LESS THAN OR EQUAL TO x <= y Will return true if x is less than or equal to y

© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved


CONDITIONAL STATEMENTS AND LOOPS

“if” Statements
The “if” statement checks if a certain Boolean condition is “true”. If the statement is
“true”, then the block of code following the “if” statement will be executed. If it is false
instead, the code will not be executed. The Boolean condition is contained with
parentheses and the code to be executed is contained by curly braces. An example
“if” statement is shown below:

if (x > 72) {
x = 7;
y = 3;
}
The above code will assign x the value of 7 and y the value of 3 if x was greater than
72. Otherwise, the code within the curly braces will not execute.

For more on if statements, please see the official Arduino documentation:

https://www.arduino.cc/reference/en/language/structure/control-structure/if/

“else” Statements
The else statement cannot exist on its own and can only be used after an if
statement. Else statements do not contain a Boolean condition and will always
execute their code block if the previous if condition did not evaluate to true. For
example, see the following code segment.

int x = 3;
if (x >= 72) {
x = 7;
}
else {
x = 42;
}
The above code will assign x the value of 42. Since the initial value of x is 3, which is
not greater than 72, the code following the if statement will not execute, but the code
following the else statement will.

For more on else statements, please see the official Arduino documentation:

https://www.arduino.cc/reference/en/language/structure/control-structure/else/

© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved


“else if” Statements
The “else if” statement cannot exist on its own and can only be used after an “if”
statement or another “else if” statement. “else if” statements will execute their code
block if the previous “if” or “else if” condition did not evaluate to true. It will then skip
over any remaining “else” or “else if” statements that follow it. For example, see the
following code segment.

int x = 20;
if(x >= 72) {
x = 7;
}
else if (x == 20){
x = 24;
}
else if(x >=20){
x = 0;
}
The above code will assign x the value of 24. Since the initial value of x is 20, which is
not greater than 72, the code following the “if” statement will not execute, and the next
“else if” condition will be checked. Since x is equal to 20, the code following the “else if”
block will be executed and x will take the value of 24. The last “else if” statement is
skipped, since one of the conditions in the chain proved to be true.

For more on “else if” statements, please see the official Arduino documentation:

https://www.arduino.cc/reference/en/language/structure/control-structure/else/

“for” Loops
A “for” loop repeats a block of code a specific number of times and will typically use
an increment counter to determine when it stops looping. There are three elements of
a for loop statement: the initialization, the condition, and the increment.

A typical for loop will look like as follows:

int x = 0;
for (int i = 0; i< 100; i++) {
x = x + 2;
}
The initialization is where i is declared and initialized to 1. This is executed only at the
beginning. The condition is the ‘i < 100’. This means that the “for” loop will continue
© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved
executing its code block as long as i is less than 100. The i++ is the increment, resulting
in i incrementing by 1 every time the code block is executed. The increment is
executed at the end of every iteration of the loop. That means that this “for” loop will
execute its code exactly 100 times before continuing on to the rest of the program.
The final value of x will be 200.

For more on for loops in Arduino, please see the official Arduino documentation:

https://www.arduino.cc/reference/en/language/structure/control-structure/for/

© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved


ARDUINO FUNCTIONS

The functions used in this course are outlined below for your own reference.

pinMode()
Description: Configures the specified pin to behave either as an input or an output.

Syntax: pinMode(pin, mode)

Parameters:

● pin: the Arduino pin number to set the mode of


● mode: INPUT, OUTPUT, or INPUT_PULLUP.

Return: None.

Example:

void setup() {
// sets the digital pin 13 as output
pinMode(13, OUTPUT);
}

digitalWrite()
Description: Writes a HIGH or a LOW value to a digital pin.

Syntax: digitalWrite(pin, value)

Parameters:

● pin: the Arduino pin number


● value: HIGH or LOW

Return: None.

Example:

void loop() {
// sets digital pin 13 to logic high
digitalWrite(13, HIGH);
}

delay()
© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved
Description: Stalls the program for the amount of time as specified in the input
parameter (milliseconds).

Syntax: delay(ms)

Parameters:

● ms: the number of milliseconds to stall for.

Return: None.

Example: The following example code alternates the output on pin 13 from high to low
every 1 second.

void loop() {
digitalWrite(13, HIGH);
delay(1000); // wait for 1 second
digitalWrite(13, LOW);
delay(1000); // wait for 1 second
}

digitalRead()
Description: Reads a HIGH or LOW value from a digital pin.

Syntax: digitalRead(pin)

Parameters:

● pin: the Arduino pin number to read.

Return: HIGH or LOW

Example:

void loop() {
// Reads pin 13 and stores result into val
int val = digitalWrite(13);
}

analogRead()
Description: Reads the integer value from an analog pin.

© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved


Syntax: analogRead(pin)

Parameters:

● pin: the Arduino analog input pin to read.


Return: The analog reading on the pin as an int (value between 0-1023).

Example:

void loop() {
// Reads pin A0 and stores result into val
int val = analogRead(A0);
}

analogWrite()
Description: Writes an analog value (PWM wave) to a digital pin.

Syntax: analogWrite(pin, value)

Parameters:

● pin: the Arduino pin to write, must be a PWM pin market with a ‘~’.
● value: the duty cycle (value between 0-255)

Return: None.

Example:

void loop() {
// Writes a 50% duty cycle to pin 11
analogWrite(11, 255*0.5);
}

© Copyright 2021 Gentiam Consulting LLC - All Rights Reserved

You might also like