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

Getting Started With Programming On Arduino

The document provides an overview of programming on Arduino, including key terminology like sketches and statements. It explains variables that can be used like integers, floats, strings and booleans. It also covers basic programming concepts such as control structures like if/else statements and different kinds of loops. Input/output functions are described for digital and analog reading and writing. The document emphasizes that Arduino code uses a setup function that runs once and a loop function that repeats continuously.

Uploaded by

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

Getting Started With Programming On Arduino

The document provides an overview of programming on Arduino, including key terminology like sketches and statements. It explains variables that can be used like integers, floats, strings and booleans. It also covers basic programming concepts such as control structures like if/else statements and different kinds of loops. Input/output functions are described for digital and analog reading and writing. The document emphasizes that Arduino code uses a setup function that runs once and a loop function that repeats continuously.

Uploaded by

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

Getting started with

Programming on Arduino
Terminology
● Sketch
● Syntax
● Statement
Programming code
● Variable
Programming code
● Variable

For example, this statement (called a


declaration):

int pin = 13;


Programming code
● Variable
■ int
■ float
■ string
■ boolean
Programming code
● Variable
■ int
■ float
■ string
■ boolean
● if
Control Structure

● if
Control Structure

● if

if (condition) {
//statement(s)
}
Control Structure

● if

if (condition) {
//statement(s)
} else {
//statement(s)
}
Control Structure

● loops
Control Structure

● loops
■ while (condition) {
//statement
}
ex.
int var = 0;
while (var < 200) {
// do something repetitive 200 times
var++;
}
Control Structure

● loops
■ for (initialization; condition; increment)
{
//statement
}
Control Structure

● loops
■ for (initialization; condition; increment)
{
//statement
}

for (int i = 0; i < 10; i++) {


//statement
}
Control Structure

● loops
■ do {
//statement
} while (condition);

do {
//statement
} while (a < 5);
Control Structure

● loops
■ while (condition) {
//statement
}
■ for (init; con; inc) {
//statement
}
■ do {
//statement
} while (condition);
Basic programming
● Variable
■ int
■ float
■ string
■ boolean
● if
● loops
Basic Programming

● function
Basic Programming

● function
■ delay();
ex.
delay(1000);
Input/Output
● Digital

● Analog
Input/Output
● Digital
○ digitalRead()

● Analog
○ analogRead()
Input/Output
● Digital
○ digitalRead()
� int inputValue = digitalRead(13);

// reads the value of pin 13.

● Analog
○ analogRead()
� int inputValue = analogRead(A0);

// reads the value of pin A0.


Input/Output
● Digital
○ digitalRead()
○ digitalWrite()
● Analog
○ analogRead()
○ analogWrite()
Input/Output
● Digital
○ digitalWrite()

� digitalWrite(13, LOW); // Makes the output


voltage on pin 13 , 0V

� digitalWrite(13, HIGH); // Makes the output


voltage on pin 13 , 3.3V
Input/Output
● Analog
○ analogWrite()

� analogWrite(A0, sensorValue); // Makes the


output voltage on pin A0, value of the sensor.
Input/Output
● Digital
○ digitalRead()
○ digitalWrite()
● Analog
○ analogRead()
○ analogWrite()
● pinMode()
PinMode
� A pin on arduino can be set as input or
output by using pinMode function.

pinMode(pin, mode)

� pinMode(13, OUTPUT); // sets pin 13 as


output pin

� pinMode(13, INPUT); // sets pin 13 as input


pin
Bare minimum code
void setup() {
// put your setup code here, to run once:
}

void loop() {
// put your main code here, to run
repeatedly:
}

You might also like