Skip to main content

Digital I/O

The Quarto has eight digital input and output pins, which can be utilized using standard Arduino™ functions:

pinMode

void pinMode(uint8_t pin, uint8_t mode);

This function configures the input or output characteristics of a digital pin. By default, all pins are inputs. The function takes the follow arguments:

  • pin Pin should be an integer between 1 and 8, corresponding pins D1 through D8.
  • mode sets the input or output mode. Valid options are:
    • OUTPUT: Standard output pin (3.3V CMOS push-pull)
    • OUTPUT_OPENDRAIN: Open drain output
    • INPUT: Standard input (floating)
    • INPUT_PULLUP: Input with 22k pull up resistor
    • INPUT_PULLDOWN: Input with 100k pull down resistor

Example

pinMode(1,OUTPUT);
pinMode(2,INPUT);

digitalWrite

void digitalWrite(uint8_t pin, uint8_t value);

This function sets a digital output pin HIGH or LOW. Unlike in many Arduino™ systems, there is no need to use digitalWriteFast() for better speed performance as digitalWrite() has already been optimized for speed. The function takes the following arguments:

  • pin Should be an integer between 1 and 8, corresponding pins D1 through D8.
  • value set the pin to a 0 or 1. Valid options are:
    • LOW
    • HIGH

Example

void setup() {
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
}

void loop() {
digitalWrite(1,HIGH);
digitalWrite(2,1); // same digitalWrite(2,HIGH);
digitalWrite(1,LOW);
digitalWrite(2,0); // same digitalWrite(2,LOW);
}

digitalToggle

void digitalToggle(uint8_t pin);

This function toggles the state of a digital output pin HIGH or LOW. Unlike in many Arduino™ systems, there is no need to use digitalToggleFast() for better speed performance as digitalToggle() has already been optimized for speed. The function takes the following arguments:

  • pin Should be an integer between 1 and 8, corresponding pins D1 through D8.

Example

void setup() {
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
}

void loop() {
digitalToggle(1);
digitalToggle(2);
}

digitalRead

uint8_t digitalRead(uint8_t pin);

The function returns a 0 if the digital input pin is low and returns 1 if the digital pin is high. Unlike in many Arduino™ systems, there is no need to use digitalReadFast() for better speed performance as digitalRead() has already been optimized for speed. The function takes the following arugments:

  • pin Should be an integer between 1 and 8, corresponding pins D1 through D8.

Example

void setup() {
pinMode(1,INPUT);
pinMode(2,INPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
}

void loop() {
if ( digitalRead(1) ) {
//D1 is high
digitalWrite(3,LOW);
} else {
if (digitalRead(2) == LOW) {
//D1 and D2 low
digitalWrite(4,HIGH);
} else {
//D1 Low, D2 high
digitalWrite(4,LOW);
}
}
}