Arduino Programming Basics
Arduino Programming Basics
Basics
pinMode()
Description The pinMode() method sets the specified digital I/O pin as INPUT or OUTPUT. A
digital or binary I/O pin can have two possible values: HIGH or LOW. Is it possible to set
or read the value of a digital I/O pin by using the digitalWrite() and digitalRead()
methods.
Examples:
• pinMode(8, INPUT); // set the pin 8 as an input pin
• pinMode(WLED, OUTPUT); // set the pin WLED as an output pin
• portMode(1, OUTPUT); // set port 1 as an output port
setup()
Description
Function called once when the program begins running. Used to define initial environment
properties such as a pin mode (INPUT or OUTPUT), starting the serial port etc. before the
loop () begins executing. Variables declared within setup () are not accessible within loop().
Syntax loop() {
statements
}
Description The digitalWrite() method sets the value of a digital output pin.
Possible values are HIGH or LOW.
Syntax digitalWrite(pin,value)
Description The digitalRead() method reads the value of a digital input pin.
Syntax digitalRead(pin)
Syntax delay(milliseconds)
Syntax analogRead(pin)
Description The analogWrite() method sets the value of a PWM output pin. By default possible
values range from 0-255. On Wiring v1 boards the PWM capable pins are: 29, 30, 31,
35, 36 and 37. On Wiring S board the PWM capable pins are: 4, 5, 6, 7, 19 and 20.
Note: analogWrite is an alias for the PWMWrite() command.
Doing analogWrite() on a non PWM pin will cause the pin to
be set to HIGH with no other effect.
Syntax analogWrite(pin,value)
Parameters
• value float: The incoming value to be converted
• low1 float: Lower bound of the values current range
• high1 float: Upper bound of the values current range
• low2 float: Lower bound of the values target range
• high2 float: Upper bound of the values target range