Datasheet
Note that we made the code a little less 'pythonic' than necessary, the if/then could be replaced with a simple led.value
= not button.value but I wanted to make it super clear how to test the inputs. When the interpreter gets to evaluating
button.value that is when it will read the digital input.
Press Button A (the one on the left), and the onboard red LED will turn on!
Note that on the M0/SAMD based CircuitPython boards, at least, you can also have internal pullups with Pull.UP when
using external buttons, but the built in buttons require Pull.DOWN.
Maybe you're setting up your own external button with pullup or pulldown resistor. If you want to turn off the internal
pullup/pulldown just assign button.pull = None
Going Beyond the Lesson!
It's time to flex your new learnings and try something different!!
Experiment 1
See if you can adjust your code so that you use Button B instead of Button A.
It only takes a small change to switch buttons. If you get stuck, click on the blurry text below to reveal a hint and then
the answer:
You need to change one single, solitary letter!You need to change one single, solitary letter!
You need to change one single, solitary letter!
button = DigitalInOut(board.BUTTON_B)button = DigitalInOut(board.BUTTON_B)
button = DigitalInOut(board.BUTTON_B)
Experiment 2
Perhaps you want to be sure there are no accidental illuminations of the red LED! Make it so that BOTH buttons must
be pressed in order to light the red LED.
Hints:
You'll need to declare a variable for the second button, just as you did with the first. You'll also need to set it up as anYou'll need to declare a variable for the second button, just as you did with the first. You'll also need to set it up as an
You'll need to declare a variable for the second button, just as you did with the first. You'll also need to set it up as an
input, with pull down resistance.input, with pull down resistance.
input, with pull down resistance.
It's a good idea to rename the original It's a good idea to rename the original
It's a good idea to rename the original
buttonbutton
button
variable to variable to
variable to
buttonA, buttonA,
buttonA,
and the new setand the new set
and the new set
to to
to
buttonB.buttonB.
buttonB.
To check both buttons in the 'if' statement, you'll use an 'and' to string together both valueTo check both buttons in the 'if' statement, you'll use an 'and' to string together both value
To check both buttons in the 'if' statement, you'll use an 'and' to string together both value
checks. checks.
checks.
if buttonA.value == True and buttonB.value == True: if buttonA.value == True and buttonB.value == True:
if buttonA.value == True and buttonB.value == True:
Experiment 3
We're using the built-in pushbuttons in this example because it's very easy to get started, but you can use
ALL KINDS of different buttons and switches, even homemade ones such as tinfoil or pennies, as digital
inputs connected to the Digital IO pads!
© Adafruit Industries https://learn.adafruit.com/adafruit-circuit-playground-express Page 96 of 211










