Datasheet

Arduino Switches
The first part of interfacing with hardware is being able to manage digital inputs and outputs. With the built in Circuit
Playground hardware & the Arduino library it's super easy!
This quick-start example shows how you can use one of the Circuit Playground buttons as an
input
to control another
digital
output
- the built in LED
Note that we made the code a little less elegant than necessary, the if/then could be replaced with a
simple CircuitPlayground.redLED(CircuitPlayground.leftButton()) but I wanted to make it super clear how to test the inputs.
Press Button A (the one on the left), and the onboard red LED will turn on!
Without Library Assist
If you are interested in 'lower level' interfacing to the hardware, you don't
have
to use the CircuitPlayground helper
library. This code shows manually setting the button/LED pins to inputs & outputs as well as setting and reading the
state of the pins:
#include <Adafruit_CircuitPlayground.h>
void setup() {
// Initialize the circuit playground
CircuitPlayground.begin();
}
void loop() {
// If the left button is pressed....
if (CircuitPlayground.leftButton()) {
CircuitPlayground.redLED(HIGH); // LED on
} else {
CircuitPlayground.redLED(LOW); // LED off
}
}
#include <Adafruit_CircuitPlayground.h>
void setup() {
pinMode(CPLAY_LEFTBUTTON, INPUT_PULLDOWN);
pinMode(CPLAY_REDLED, OUTPUT);
}
void loop() {
// If the left button is pressed....
if (digitalRead(CPLAY_LEFTBUTTON)) {
digitalWrite(CPLAY_REDLED, HIGH); // LED on
} else {
digitalWrite(CPLAY_REDLED, LOW); // LED off
}
}
© Adafruit Industries https://learn.adafruit.com/adafruit-circuit-playground-express Page 183 of 211