Buttons

Let’s have a listen to the CPX’s speakers!

Here the first number is the pitch, and the second number is the duration of the note.

The ‘if statement’ is going to check which button we pressed, and play the correspondng note.

from adafruit_circuitplayground.express import cpx

while True:
    if cpx.button_a:
        cpx.play_tone(329,1)
        cpx.play_tone(261,1)
    elif cpx.button_b:
        cpx.play_tone(440,1)
        cpx.play_tone(400,1)
Thanks! We hope you found what you are looking for. Please feel free to contribute via Github.