Digital Outputs

Digital Outputs (DO) are one of the four contexts or types of circuits that are core to tangible.

If you have not yet looked at the tangible matrix Building Block, you should check it out now. It will introduce you to all four contexts.

Context :: Digital Output

do matrix

Digital refers to signals, circuits, or logical systems that only have two states; ON, OFF.

Input and Output are defined from the perspective of our Arduino.

Electrical signals generated by the Arduino and sent out to circuits are OUTPUTS.

So, Digital Outputs are ON/OFF signals (V) that move OUT of the Arduino.

Card

Your kit contains a reference card for digital outputs.

Each card indicates the context, command, circuit and offers a code sample.

digital output card

Video :: Digital Outputs

This first video is from a project that I completed with David Bouchard. An alternate course specific video can be found below.

tangible introduction to digital outputs. Please note — I extend the first build with an RGB LED in this video. If you have not looked at RGB LED you can just use 2 single color LEDs. It simplifies the circuit. I will post an RGB video ASAP.

Code samples from the video can be found below.

Get the Slides

Classic Example

The classic example of a digital output is a blinking LED.

Circuit

The classic circuit for testing a digital output is a simple LED and current limiting resistor. Circuit on left when state = 0, LOW, circuit on right when state = 1,HIGH.

Command :: digitalWrite()

The code that creates a Digital Output is:

    digitalWrite(pin, state);

where:
pin = 2 – 13 (inclusive)
state = LOW (0, Ground) OR HIGH (1, 5V)

Note 1: pin can also include 0,1; but these are reserved for communication, so best to avoid them. Note 2: pin 13 has the built in LED attached

The line of code above means:

Write a digital (on/off) signal to pin at level = state (0/LOW or 1/HIGH).

How Does it Work?

If a 1 or HIGH is written, then the voltage (V) at the pin is set to 5V.

If a 0 or LOW is written, then the voltage (V) at the pin is set to 0V (ground).

Important

In Arduino, we Write outputs. Image creating waterfalls on the selected pin.

Check the Arduino Docs for this topic

Code Sample – SINGLE LED

int ledPin  = 5 ; // led on pin 5

void setup() {
  pinMode ( ledPin , OUTPUT) ; // set direction
}

void loop() {

  digitalWrite ( ledPin , 1 ) ;   // turn LED on
  delay ( 1000 ) ;  // wait a bit == 1 second

  digitalWrite ( ledPin, 0 ) ;  // turn LED off  
  delay ( 1000 ) ; // wait a bit

}

CODE Sample – 2 colors of RGB LED

// code sample using B and R, of RGB led

int blueLED  = 5 ;  // connect PIN 5 to BLUE pin of RGB LED
int redLED   = 10 ; // connect PIN 10 to RED pin of RGB LED

void setup() { 
  // put your setup code here, to run once:
  pinMode ( blueLED , OUTPUT) ;   
  pinMode ( redLED  , OUTPUT) ; 
}

void loop() { 
  // put your main code here, to run repeatedly:

  //  blue
  digitalWrite ( blueLED , HIGH ) ;   // turn LED on 
  delay ( 1000 ) ;  // wait a bit == 1 second 
  digitalWrite ( blueLED, LOW ) ;  // turn LED off  
  delay  (1000 ) ; // wait a bit 

  //  red
  digitalWrite ( redLED , HIGH ) ; 
  delay ( 1000 ) ;  // wait a bit == 1 second 
  digitalWrite ( redLED, LOW ) ;  // turn LED off  
  delay  (1000 ) ; // wait a bit 
}

Going Further

Some follow up Arduino references:

pinMode

Serial

Leave a Reply

Your email address will not be published. Required fields are marked *