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.
/////////////////////////////////////////////////////////////////////////////// // 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
This sets the voltage of the digital input to 0V (LOW). You should see 0s scroll by in the Serial Monitor.
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.
Page last edited February 22, 2017
Text editor powered by tinymce.