Quarter II - Computer Science Reviewer - Ray
Quarter II - Computer Science Reviewer - Ray
REVIEWER
Arduino Programming
ARDUINO
• Arduino is an open-source project that created microcontroller-based kits for
building digital devices and interactive objects that can sense and control
physical devices.
• Is an open-source electronics platform based on easy-to-use hardware and
software.
Two major parts:
1. Arduino board
- which is the piece of hardware where we can work on or where we build
our projects
2. IDE (Integrated Development Environment)
- which is the software/application/program that we will run on our
computer/machine
MICROCONTROLLER
• A small computer on a single integrated circuit containing a processor core,
memory, and programmable input/output peripherals.
• The most important part for us is that a microcontroller contains a processor
(which all computers have, even smartphones) and memory, and some
input/output pins that we can control.
GPIO – General Purpose Input Output Pins
- Input/output pins that we can control.
Examples of microcontrollers:
Raspberry Pi – color Green
Arduino – color Blue
EZboard – color Blue
- low power consumption Arduino™ compatible board, equipped with an
onboard WiFi controller, microSD card socket, temperature sensor, and
power relay.
GizDuino mini – color Red, made in the Philippines
ARDUINO SOFTWARE
IDE (Integrated Development Environment)
• Software used to program the Arduino board (microcontroller).
• Minimum requirement : MAC OS X; Windows XP 32-bit or 64-bit; Linux 32-
bit or 64-bit (Ubunto or similar)
Sketch
• It is the name that the Arduino program is called.
• Is a set of lines or instructions that will tell the board on what to do.
• It is based on a C/C++ platform.
• Arduino programs can be divided in three main parts: structure, values
(variables and constants), and functions.
SKETCH FLOW
if() statement (Conditional Statement)
• most basic of all programming control structures. It allows you to
make something happen or not, depending on whether a given
condition is true or not. It looks like this:
if (someCondition) {
// do stuff if the condition is true
}
SYNTAX
; (semicolon)
- Used to end a statement.
- Forgetting to end a line in a semicolon will result in a compiler error.
{} (curly braces)
– Used for function(s), indicating start and finish of a function(s).
- it is used for loops, conditional statements.
________________________________________________________________
DIGITAL i/o
pinMode()
- Configures the specified pin to behave either as an input or an output. See the
description of digital pins for details on the functionality of the pins.
Syntax : pinMode(pin, mode)
Parameters
pin: the number of the pin whose mode you wish to set
mode: INPUT, OUTPUT
Returns : None
Example
pinMode(13,OUTPUT);
digitalWrite()
-Write a HIGH or a LOW value to a digital pin.
-If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set
to the corresponding value: 5V for HIGH, 0V (ground) for LOW.
-If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable
(LOW).
Syntax
digitalWrite(pin, value)
Parameters
pin: the pin number
value: HIGH or LOW
Returns : None
Example : digitalWrite(13, HIGH);
digitalRead()
- Reads the value from a specified digital pin, either HIGH or LOW.
Syntax
digitalRead(pin)
Parameters
pin: the number of the digital pin you want to read (int)
Returns : HIGH or LOW
Example : val = digitalRead(13);
DELAY
delay()
- Pauses the program for the amount of time (in miliseconds) specified as
parameter. (There are 1000 milliseconds in a second.)
Syntax
delay(ms)
Parameters
ms: the number of milliseconds to pause.
Returns : nothing
Example : delay(1000);
VARIABLE DECLARATION
Variable
- is a way of naming and storing a value for later use by the program, such as data
from a sensor or an intermediate value used in a calculation.
Declaring Variables
• Before they are used, all variables have to be declared. Declaring a variable
means defining its type, and optionally, setting an initial value (initializing the
variable). Variables do not have to be initialized (assigned a value) when they
are declared, but it is often useful.
Example:
int inputVariable1;
int inputVariable2 = 0;
ARDUINO
Microchip
- Very small computer that you can program to respond to things
- Measure conditions (like how much light there is in the room)
- Can control how other objects react to those conditions (room gets dark and
an LED turns on.
- Can respond to something as simple as the press of a switch
Mouse
- Common input device for a desktop computer
Monitor
- Common output device for a desktop computer
Microcontrollers
- Use inputs and outputs
Inputs – capture information from the user or the environment
Outputs – do something with the information that has been captured
- Any object we want to turn on and off and control; could be a motor or even a
computer
Switch or Sensor
- Could be an input into the Arduino
A switch is a digital input, a sensor is an analog input. The range of an analog sensor
is limited by its conversion to digital data.
TWO COMMON TYPES OF CIRCUITS
1. Direct Current – current always flows in one direction
2. Alternating Current – current flows in opposite directions in regular cycles
Activity 6:
(Lack of information since sir Julius haven’t give us the activity 6 paper)