Basic Print

Let's start simple. This sketch prints a unique message for each touch pad. Download it and load it to the Circuit Playground.

With this sketch loaded and running on the Circuit Playground, open the Serial Monitor.

Tools -> Serial Monitor

Now press any of the 8 touch pads. You should see a message printed out for each one.

Take a look at the loop() function in this sketch. The main change from the previous sketch is the addition of an outer for loop which scans over each of the touch pads on the Circuit Playground.

void loop() {
  // Loop over every pad.
  for (int i=0; i<numberOfPads; i++) {
    
    // Check if pad is touched.
    if (capButton(pads[i])) {
      
      // Do something.
      takeAction(pads[i]);
      
      // But not too often.
      delay(DEBOUNCE);
    }
  }
}

The variable numberOfPads and the array pads[] have been defined globally near the top of the sketch. The sequence of the numbers in pads[] is such that they are scanned in a counter-clockwise fashion starting with pad #3.

uint8_t pads[] = {3, 2, 0, 1, 12, 6, 9, 10};
uint8_t numberOfPads = sizeof(pads)/sizeof(uint8_t);

Also, a new function called takeAction() has been created. This allows us to use this same loop() setup for all of the sketches. All we have to do is change the code in takeAction() to change the behavior of the Circuit Playground.

If you look at the code in takeAction() you will see it contains a switch statement. This is where the main plumbing between Circuit Playground touch pads and actual code takes place. The case statements correspond to pad numbers and the code inside the case statement defines what is executed for each pad.

For example, for pad #12, the following lines of code are executed:

      Serial.println("I'm Idaho!");
      break;

The break is needed to exit out of the switch statement.

Keen. Now let's do something a little more exciting than just printing out Simpsons quotes.

Last updated on 2016-11-14 at 03.34.38 PM Published on 2016-11-15 at 03.44.24 PM