Introduction: St. Patrick's Day "Pinch Detector" With Circuit Playground

St. Patrick's day falls on a Friday this year. Take your Circuit Playground to work, school, or a party and be "that guy" who brings a Pinch Detector.

For this project you will need:

- Circuit Playground

- Data sync cable*

*Make sure it is not a "charge only cable" or you will not be able to upload programs to your Circuit Playground.

clipartfox.com

Step 1: Add Circuit Playground to Arduino

Picture of Add Circuit Playground to Arduino

Install a driver, board manager, and library for Circuit Playground.

Complete instructions can be found at our site. Installation tips start at page 17.

Step 2: Navigate to "color_sense" Example.

Picture of Navigate to "color_sense" Example.

We will be using the "color_sense" program as a base for our project.

File>>
  Examples>>
    Adafruit Circuit Playground>>
      color_sense

Step 3: Adding Tones to the Color_sense Program.

Picture of Adding Tones to the Color_sense Program.

The color_sense program makes use of the built in Light Sensor on the Circuit Playground and displays the color back on the board's 10 Neo Pixels when either button is pressed.

We will be inserting a few lines of code to make use of the built in Speaker. If the board detects a green color from the Light Sensor it will play a higher pitched "ding-ding-ding" sound. Anything not green will get a lower sounding "ding-dong" sound .

This code compares the intensity of green light to both the red and the blue readings. If green returns the highest value, the 3 dings will sound.

CircuitPlayground.playTone(frequency, duration_milliseconds)

Frequency is measured in Hz.

Step 4: Insert Code

Picture of Insert Code

In the color_sense program navigate to

File>> Save as...>>

Save it under a new name such as "Circuit_SeeingGreen".

Insert code at the bottom, just below the for loop as shown in the picture. Or download the attached code.

if (green > red && green > blue) {

CircuitPlayground.playTone(554, 350);

CircuitPlayground.playTone(0, 50);

CircuitPlayground.playTone(554, 350);

CircuitPlayground.playTone(0, 50);

CircuitPlayground.playTone(554, 500);

}

else {

CircuitPlayground.playTone(290, 350);

CircuitPlayground.playTone(0, 250);

CircuitPlayground.playTone(200, 600);

}

Comments