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 set
mode: INPUT or OUTPUT
Returns
None

digitalWrite

Description
Write a HIGH or a 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 pin number
Returns
HIGH or LOW

Sample Program

Sample for digitalWrite and digitalRead.


#include <Arduino.h>
#define INTERVAL 100
    
void setup()
{
    pinMode(PIN_LED_RED   , OUTPUT);
    pinMode(PIN_LED_GREEN , OUTPUT);
    pinMode(PIN_LED_BLUE  , OUTPUT);
    pinMode(PIN_LED_USER  , OUTPUT);
    pinMode(PIN_SW        , INPUT);
}
    
void loop()
{
    while(digitalRead(PIN_SW) == 0){
        digitalWrite(PIN_LED_USER, 1);
        delay(INTERVAL);
        digitalWrite(PIN_LED_USER, 0);
        delay(INTERVAL);
    }
    digitalWrite(PIN_LED_RED, 1);
    delay(INTERVAL);
    digitalWrite(PIN_LED_RED, 0);
    digitalWrite(PIN_LED_GREEN, 1);
    delay(INTERVAL);
    digitalWrite(PIN_LED_GREEN, 0);
    digitalWrite(PIN_LED_BLUE, 1);
    delay(INTERVAL);
    digitalWrite(PIN_LED_BLUE, 0);
    
}