Basic Library
Digital I/O
Analog I/O
Advanced I/O
Time
Math
Trigonometry
Random Numbers
Bits and Bytes
Interrupts
Serial Comm.
Standard Library
Ethernet
Ethernet (Server)
Ethernet (Client)
Servo Motor
Stepping Motor
Character LCD
EEPROM
SPI
I2C (Wire)
SD
SD (File Operations)
Image Processing
Periodic Operation
Clock (RTC)
Utility
Digital I/O
This library is for configuring the digital signal (HIGH/LOW) to function as either input or output.
pinMode
- Description
- Configures the specified pin to behave either as an input or an output.
- Syntax
- pinMode(pin, mode)
- Parameters
- pin: The number of the pin to be set.
mode:
INPUT
OUTPUT
INPUT_PULLUP (pullup then input)
OUTPUT_HIGH (enable 2 times current)
OUTPUT_OPENDRAIN - Returns
- None
digitalWrite
- Description
- Writes a HIGH or LOW value to a digital pin.
- Syntax
- digitalWrite(uint8_t pin, uint8_t value)
- Parameters
- pin: The pin number
value: HIGH or LOW - Returns
- None
digitalRead
- Description
- Reads the value from a specified digital pin, either HIGH or LOW.
- Syntax
- digitalRead(uint8_t pin)
- Parameters
- pin: The number of the digital pin you want to read
- Returns
- HIGH or LOW
Sample Program
Sample for digitalWrite and digitalRead.
#include <Arduino.h>
void setup()
{
pinMode(PIN_LED0, OUTPUT);
pinMode(PIN_LED1, OUTPUT);
pinMode(PIN_SW, INPUT);
}
void loop()
{
if(digitalRead(PIN_SW) == 0){
digitalWrite(PIN_LED0, HIGH);
digitalWrite(PIN_LED1, LOW);
} else {
digitalWrite(PIN_LED1, HIGH);
digitalWrite(PIN_LED0, LOW);
}
}