Simple digital components can either be on or off. Interacting with them is straightforward.

Button LED socket

Hardware

Those included in the Beginner Kit (button, LED) are connected to the digital port specified on the Beginner Kit board; external Grove components can be connected to one of the analog ("D") ports on the Grove shield:

Digital ports on the Grove Beginner Kit shield

Software

Functions for interacting with digital pins are prefixed with digital.

Initialization

No special initialization is required for interacting with digital components.

Reading from digital pins

def digital_read(pin):
    """Read a value from a digital port.

    Parameters:
      pin (int):     Digital pin to read from (e.g., 4 for D4).

    Returns:         True or False.
    """

Writing to digital pins

To write a digital value to an actuator such as an LED socket or a relay, use the digital_write function provided by our Arduino library.

def digital_write(pin, value):
    """Write a value to a digital port.

    Parameters:
      pin (int):     Digital pin to write to (e.g., 4 for D4).
      value (bool):  Value to write (True or False).
    """