Circuit Playground Board

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
BillBall
 
Posts: 2
Joined: Wed May 04, 2016 12:04 pm

Circuit Playground Board

Post by BillBall »

I'd like to get a discussion going about using the new Circuit Playground board (https://www.adafruit.com/product/3000) in learning environments. This seems to be a near ideal product for introducing people to physical computing.
For example (when combined with the new serial plotter option in the Arduino IDE 1.6.8) this simple sketch:

Code: Select all

#include <Adafruit_CircuitPlayground.h>

void setup() {
 Serial.begin(9600);
 CircuitPlayground.begin();
}

void loop() {
  Serial.println(CircuitPlayground.lightSensor());
}
Plots light values. The same can be done with the other input sensors. $20 and 6 lines of code and you're plotting environmental data.

So as people who currently have the developer version of the board start putting together some educational applications of it, it would be great if they could post links to their projects here. I will do the same.
Last edited by Franklin97355 on Wed May 04, 2016 12:53 pm, edited 1 time in total.
Reason: Added missing [code]...[/code] tags.

User avatar
BillBall
 
Posts: 2
Joined: Wed May 04, 2016 12:04 pm

Re: Circuit Playground Board

Post by BillBall »

I've attached a sketch that uses the microphone and neopixels to create a basic sound level volume meter.
I haven't found documentation on the CircuitPlayground.colorWheel() function but the color wheel assignments seem to be in this pattern: 0 = Red, 85 = Green, and 170 = Blue.
The microphone levels work ok for my environment but it would be nice to squeeze more range out of it.

Code: Select all

// example of a linear volume meter. Bill Ball www.robot50.net

// include the Circuit Playground library
#include <Adafruit_CircuitPlayground.h>

// create a variable to hold the sound level
 uint8_t volume = 0;
 
void setup() {

  // remove the comments to open the serial port if it's needed 
  //Serial.begin(9600);
 
  // start Circuit Playground
  CircuitPlayground.begin();
  }

void loop() {

     // clear all lit pixels 
     CircuitPlayground.clearPixels();

    // set a sample and display rate in milliseconds
    delay(5);

    // measure the sound
    volume = CircuitPlayground.soundSensor();
  
    // set the pixels based on the sound level
    // this could be written more compactly but
    // it is a good opportunity to show how if/else works.

    if (volume < 110) {
      // do nothing;
    } else
    if (volume < 125) {
      CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    } else
    if (volume  < 145) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    } else
    if (volume  < 160) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    } else
    if (volume < 175) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    } else
    if (volume < 190) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    } else
    if (volume < 205) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    } else
    if (volume < 220) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(60));
    } else
     if (volume < 235) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(60));
    CircuitPlayground.setPixelColor(2, CircuitPlayground.colorWheel(30));
    } else
    if (volume < 250) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(65));
    CircuitPlayground.setPixelColor(2, CircuitPlayground.colorWheel(30));
    CircuitPlayground.setPixelColor(1, CircuitPlayground.colorWheel(10));
    } else 
    if (volume > 249) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(60));
    CircuitPlayground.setPixelColor(2, CircuitPlayground.colorWheel(30));
    CircuitPlayground.setPixelColor(1, CircuitPlayground.colorWheel(10));
    CircuitPlayground.setPixelColor(0, CircuitPlayground.colorWheel(0));
    }

} // end of main loop

User avatar
mnelsonhotjobs
 
Posts: 130
Joined: Sun Mar 06, 2016 5:27 pm

Re: Circuit Playground Board

Post by mnelsonhotjobs »

Nice! Thank you for that BillBall! I was going to create something similar and then wondered if anyone already had. I've integrated yours into one that I've been working on (just modding the demo to death haha). I also want to create a tilt sensor one that lights whichever LEDs are up. I think that's going to be complicated though....we'll see. Here's the modded demo I have so far:

Code: Select all

// Demo program for testing library and board - flip the switch to turn on/off buzzer

#include <Adafruit_CircuitPlayground.h>

// we light one pixel at a time, this is our counter
 uint8_t pixeln = 0;
// create a variable to hold the sound level
 uint8_t volume = 0;

void setup() {
  //while (!Serial);
  Serial.begin(9600);
  Serial.println("Circuit Playground test!");

  CircuitPlayground.begin();
}

void loop() {
  
  /************* TEST SLIDE SWITCH */
  if (CircuitPlayground.slideSwitch()) {
    Serial.println("Slide to the left");
    playGame();
  } else {
    Serial.println("Slide to the right");
    volMeter();
 }

}

void leftPlay() {
  for (int doagain = 0; doagain < 10; doagain++) {
    for (int pixeln = -1; pixeln < 10; pixeln++){
      CircuitPlayground.setPixelColor(pixeln, CircuitPlayground.colorWheel(25 * pixeln));
      CircuitPlayground.playTone(500 + pixeln * 500, 250);
      delay(50);
    }
      
      pixeln = 0;
      CircuitPlayground.clearPixels();
      delay(50);
    
    
  }
}

void playGame(){

    if (CircuitPlayground.leftButton()) {
    leftPlay();
    }
    
  if (CircuitPlayground.readCap(3)> 30) {
    int touch = CircuitPlayground.readCap(3);
    CircuitPlayground.playTone(500, 500);
    CircuitPlayground.setPixelColor(0, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(1, CircuitPlayground.colorWheel(2 * touch));
    //CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(5 * touch));
    delay(500);
    CircuitPlayground.clearPixels();
  }
  if (CircuitPlayground.readCap(2)> 30) {
    int touch = CircuitPlayground.readCap(2);
    CircuitPlayground.playTone(750, 500);
    CircuitPlayground.setPixelColor(1, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(2, CircuitPlayground.colorWheel(2 * touch));
    //CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(5 * touch));
      delay(500);
    CircuitPlayground.clearPixels();
  }
    if (CircuitPlayground.readCap(0)> 30) {
    int touch = CircuitPlayground.readCap(0);
    CircuitPlayground.playTone(1000, 500);
    CircuitPlayground.setPixelColor(2, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(2 * touch));
    //CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(5 * touch));
      delay(500);
    CircuitPlayground.clearPixels();
  }
      if (CircuitPlayground.readCap(1)> 30) {
    int touch = CircuitPlayground.readCap(1);
    CircuitPlayground.playTone(1250, 500);
    //CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(2 * touch));
      delay(500);
    CircuitPlayground.clearPixels();
  }
    if (CircuitPlayground.readCap(12)> 30) {
    int touch = CircuitPlayground.readCap(12);
    CircuitPlayground.playTone(1500, 500);
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(2 * touch));
    //CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(5 * touch));
      delay(500);
    CircuitPlayground.clearPixels();
  }
  if (CircuitPlayground.readCap(6)> 30) {
    int touch = CircuitPlayground.readCap(6);
    CircuitPlayground.playTone(1750, 500);
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(2 * touch));
    //CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(5 * touch));
      delay(500);
    CircuitPlayground.clearPixels();
  }
    if (CircuitPlayground.readCap(9)> 30) {
    int touch = CircuitPlayground.readCap(9);
    CircuitPlayground.playTone(2000, 500);
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(2 * touch));
    //CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(5 * touch));
      delay(500);
    CircuitPlayground.clearPixels();
  }
    if (CircuitPlayground.readCap(10)> 30) {
    int touch = CircuitPlayground.readCap(10);
    CircuitPlayground.playTone(2250, 500);
    //CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(1 * touch));
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(2 * touch));
      delay(500);
    CircuitPlayground.clearPixels();
  }
  
  
}

void volMeter() {
       // clear all lit pixels 
     CircuitPlayground.clearPixels();

    // set a sample and display rate in milliseconds
    delay(5);

    // measure the sound
    volume = CircuitPlayground.soundSensor();
  
    // set the pixels based on the sound level
    // this could be written more compactly but
    // it is a good opportunity to show how if/else works.

    if (volume < 110) {
      // do nothing;
    } else
    if (volume < 125) {
      CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    } else
    if (volume  < 145) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    } else
    if (volume  < 160) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    } else
    if (volume < 175) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    } else
    if (volume < 190) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    } else
    if (volume < 205) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    } else
    if (volume < 220) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(60));
    } else
     if (volume < 235) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(60));
    CircuitPlayground.setPixelColor(2, CircuitPlayground.colorWheel(30));
    } else
    if (volume < 250) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(65));
    CircuitPlayground.setPixelColor(2, CircuitPlayground.colorWheel(30));
    CircuitPlayground.setPixelColor(1, CircuitPlayground.colorWheel(10));
    } else 
    if (volume > 249) {
    CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel(85));
    CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(60));
    CircuitPlayground.setPixelColor(2, CircuitPlayground.colorWheel(30));
    CircuitPlayground.setPixelColor(1, CircuitPlayground.colorWheel(10));
    CircuitPlayground.setPixelColor(0, CircuitPlayground.colorWheel(0));
    }
}



User avatar
mnelsonhotjobs
 
Posts: 130
Joined: Sun Mar 06, 2016 5:27 pm

Re: Circuit Playground Board

Post by mnelsonhotjobs »

Realizing now that if you create your sketch with the idea in mind - you can end up with up to 6 different functions of the board just using the switch and two buttons...or maybe more if you're creative about reading multiple button presses or use the sensors to switch "modes". Cool. I guess you could really do that with any of the boards but for the most part I've been doing mostly "read pin x" and then "do whatever x" based on that reading and go back to the main loop. I never had a reason to do otherwise (maybe with the exception of using an interrupt to halt completely and alarm until the offending condition was removed).

User avatar
mnelsonhotjobs
 
Posts: 130
Joined: Sun Mar 06, 2016 5:27 pm

Re: Circuit Playground Board

Post by mnelsonhotjobs »

Here's a rough for the motion sensor. I'm sure the numbers and calculations need tweaking:

Edit - improved somewhat:

Code: Select all

void tiltRead() {
    int noButton = 0;
      
    while (noButton == 0) {
      if (CircuitPlayground.rightButton()) {
        noButton = 1;
      }
      tiltx = CircuitPlayground.motionX();
      tilty = CircuitPlayground.motionY();
       
      CircuitPlayground.setPixelColor(0, CircuitPlayground.colorWheel((tiltx + (tilty / 5)) * 30));
      CircuitPlayground.setPixelColor(9, CircuitPlayground.colorWheel((tiltx - (tilty / 5)) * 30));
      CircuitPlayground.setPixelColor(4, CircuitPlayground.colorWheel((-tiltx + (tilty / 5)) * 30));
      CircuitPlayground.setPixelColor(5, CircuitPlayground.colorWheel((-tiltx - (tilty / 5)) * 30));

      CircuitPlayground.setPixelColor(2, CircuitPlayground.colorWheel(tilty * 30));
      CircuitPlayground.setPixelColor(7, CircuitPlayground.colorWheel(-tilty * 30));

      CircuitPlayground.setPixelColor(1, CircuitPlayground.colorWheel((tiltx + (1.2 * tilty)) * 20));
      CircuitPlayground.setPixelColor(8, CircuitPlayground.colorWheel((tiltx + (1.2 * -tilty)) * 20));

      CircuitPlayground.setPixelColor(3, CircuitPlayground.colorWheel(((1.2 * tilty) - tiltx) * 20));
      CircuitPlayground.setPixelColor(6, CircuitPlayground.colorWheel(((1.2 * -tilty) + -tiltx) * 20));
            
  }
  volMeter();
}

User avatar
mpc823
 
Posts: 66
Joined: Thu May 05, 2016 9:10 am

Re: Circuit Playground Board

Post by mpc823 »

I just got the Circuit Playground today and am really liking it. I think it will be perfect for a beginner class on programming. One thing I noticed is that the buttons don't appear to be debounced in hardware, so a software version is helpful. I've implemented a couple of my own debounce functions. Without some sort of debouncing, one press of the button will give a number of reads. There may be other ways you want to debounce, especially if you don't want to delay during a loop, but this is working for me.

Code: Select all

boolean CircuitPlayground::rightButtonLatched(void) {
  boolean currentDown = CircuitPlayground.rightButton();
    if (currentDown && !rightDown){
          delay(50);
          if (CircuitPlayground.rightButton()) {
            rightDown = true;
            return true;
          }
    }
    if (!currentDown && rightDown) {
          delay(50);
          if (!CircuitPlayground.rightButton()) {
            rightDown = false;
          }
    }
    return false;
}

boolean CircuitPlayground::leftButtonLatched(void) {
  boolean currentDown = CircuitPlayground.leftButton();
    if (currentDown && !leftDown){
          delay(50);
          if (CircuitPlayground.leftButton()) {
            leftDown = true;
            return true;
          }
    }
    if (!currentDown && leftDown) {
          delay(50);
          if (!CircuitPlayground.leftButton()) {
            leftDown = false;
          }
    }
    return false;
}
I also added a couple of class members for the leftDown and rightDown variables and initialized them to zero in the begin() function.

Daniel

Locked
Please be positive and constructive with your questions and comments.

Return to “For Educators”