Starting Point

We will start with a fully functional program. In fact, the functionality will not change throughout this guide.

First, let's assign functions to the two push buttons. We'll use the left button to indicate YES and the right button indicate NO as shown in the figure below.

And here is our starting version of the code.

Download: file
///////////////////////////////////////////////////////////////////////////////
// Circuit Playground Yes No v0
//
// One beep (left button) = Yes
// Two beeps (right button) = No
//
// Author: Carter Nelson
// MIT License (https://opensource.org/licenses/MIT)

#include <Adafruit_CircuitPlayground.h>

///////////////////////////////////////////////////////////////////////////////
void setup() {
  CircuitPlayground.begin();
}

///////////////////////////////////////////////////////////////////////////////
void loop() {
  if (CircuitPlayground.leftButton()) {
    //
    // YES
    //
    for (int p=0; p<10; p++) {
      CircuitPlayground.setPixelColor(p, 0xFF6600);
    }
    CircuitPlayground.playTone(700, 750);
    CircuitPlayground.clearPixels();
  }  
  if (CircuitPlayground.rightButton()) {
    //
    // NO
    //
    for (int p=0; p<10; p++) {
      CircuitPlayground.setPixelColor(p, 0xFF6600);
    }
    CircuitPlayground.playTone(700, 500);
    CircuitPlayground.clearPixels();    
    delay(250);
    for (int p=0; p<10; p++) {
      CircuitPlayground.setPixelColor(p, 0xFF6600);
    }
    CircuitPlayground.playTone(700, 500);
    CircuitPlayground.clearPixels();     
  }
}

With this program loaded and running on the Circuit Playground, you should be able to press the buttons to create the Yes/No beeps. The NeoPixels also light up.

This guide was first published on Jan 23, 2017. It was last updated on Jan 23, 2017.
This page (Starting Point) was last updated on Jul 13, 2020.