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.

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

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.

Download: file
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:

Download: file
      Serial.println("I'm Idaho!");

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.

This guide was first published on Nov 15, 2016. It was last updated on Nov 15, 2016.
This page (Basic Print) was last updated on Jul 08, 2020.