Hello Digital

Alright, let's start super simple. To read the digital value on the #3 pad, we will use the Arduino library function digitalRead. You can use the following sketch to read and print the value.

Download: file
///////////////////////////////////////////////////////////////////////////////
// Circuit Playground Digital In - Hello Digital
//
// Author: Carter Nelson
// MIT License (https://opensource.org/licenses/MIT)

#include <Adafruit_CircuitPlayground.h>

///////////////////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600);
  
  CircuitPlayground.begin();
  
  pinMode(3, INPUT);
}

///////////////////////////////////////////////////////////////////////////////
void loop() {
  int reading = digitalRead(3);
  
  Serial.println(reading);
  
  delay(500);
}

With this code loaded and running on the Circuit Playground, open the Serial Monitor.

Tools -> Serial Monitor

Now touch the BLACK clip to the BLUE clip.

This sets the voltage of the digital input to 0V (LOW). You should see 0s scroll by in the Serial Monitor.

Now touch the RED clip to the BLUE clip.

This sets the voltage of the digital input to 3.3V (HIGH). You should see 1s scroll by in the Serial Monitor.

Pretty straight forward. When the digital input pin is connected to 0V (GND) it is LOW and prints out 0s. When the digital input pin is connected to 3.3V it is HIGH and prints out 1s.

And there are our two values, 0 (LOW) and 1 (HIGH). So we're done, right? Of course not. Just getting started.

What about the case where neither the BLACK nor the RED are touching the BLUE clip? Is that LOW? Is that HIGH? Truth is, I don't know. And no one does, not even the Circuit Playground. The poor little BLUE alligator clip is floating in space not tied to any known value. This is called a "floating input" and we'll look at how to deal with this next.

This guide was first published on Feb 26, 2017. It was last updated on Feb 26, 2017. This page (Hello Digital) was last updated on Nov 20, 2019.