Digital I/O

This GR-COTTON sketch reference library is used to input/output a digital signal (0 or 1).

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 whose mode you wish to set
mode: INPUT, OUTPUT or INPUT_PULLUP
Returns
None
Remark
Analog pins A0 to A5 (14 to 21) have no internal pull-up registers. Do not specify INPUT_PULLUP for these pins.

digitalWrite

Description
Write a HIGH or a LOW value to a digital pin. If the pin is configured as an INPUT, writing a HIGH value with digitalWrite() will enable an internal pullup resistor. Writing LOW will disable the pullup
Syntax
digitalWrite(pin, 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
digitaRead(pin)
Parameters
pin: The number of the digital pin you want to read
Returns
HIGH or LOW

Example

When connecting an LED to the 0 pin, the LED is lit periodically.


#include <Arduino.h>
void setup()
{
    pinMode(0, OUTPUT);
}
 
void loop()
{
    digitalWrite(0, 1);
    delay(100);
    digitalWrite(0, 0);
    delay(100);
}