digitalWrite() — Maple v0.0.9 Documentation

### Navigation

- next
- previous |
- LeafLabs |
- Docs Home |
- Index »
- Complete Language Index »

# digitalWrite()

Write a HIGH or a LOW value to a pin configured as OUTPUT.

## Library Documentation

void digitalWrite(uint8 pin, uint8 value)

  Writes a (digital) value to a pin.

  The pin must have its mode set to `OUTPUT` or `OUTPUT_OPEN_DRAIN`.

  Parameters

  - `pin` -

    Pin to write to. One of: 0-38 (pin numbers as labeled on silkscreen), or D0-D38 (symbols for same)

  - `value` -

    Either LOW (write a 0) or HIGH (write a 1).

  See
    pinMode()

## Discussion

If the pin has been configured as an `OUTPUT` with pinMode() its voltage will be set to the corresponding value: 3.3V for `HIGH`, and 0V (ground) for `LOW`.

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. The pullup resistor is enough to light an LED dimly, so if LEDs appear to work, but very dimly, this is a likely cause. The remedy is to set the pin to an output with the pinMode() function.

Note

Pin 13 is harder to use as an input than the other pins because it has an LED and resistor soldered to it in series. If you enable its internal pull-up resistor, it will likely hang at around 1.1V instead of the expected 3.3V because the onboard LED and series resistor pull the voltage level down. If you must use pin 13 as a digital input, use an external pull-down resistor.

## Example

The following example sets pin 13 to `HIGH`, makes a one-second-long delay, sets the pin back to `LOW`, and delays again, causing a blinking pattern:

    int ledPin = 13;                 // LED connected to digital pin 13

    void setup() {
      pinMode(ledPin, OUTPUT);      // sets the digital pin as output
    }

    void loop() {
      digitalWrite(ledPin, HIGH);   // sets the LED on
      delay(1000);                  // waits for a second
      digitalWrite(ledPin, LOW);    // sets the LED off
      delay(1000);                  // waits for a second
    }

## See Also

- pinMode
- digitalRead

License and Attribution

This documentation page was adapted from the Arduino Reference Documentation, which is released under a Creative Commons Attribution-ShareAlike 3.0 License.

### Navigation

- next
- previous |
- LeafLabs |
- Docs Home |
- Index »
- Complete Language Index »