The google drive folder (to the right) has all the Arduino sketches.
CPBlinkAllNeoPixels
blinks all the onboard neopixels
CPBlinkNeoPixel
blinks a single neopixel (set the index value using the variable neopixel at the top)
CPCapLights
Allows capacitive touch to the 7 pads on the CPE and lights the closest onboard neopixel in response
See below for how to extend the touch to copper tape
CPCapPiano
Allows capacitive touch to the 7 pads on the CPE and plays a note in response using the onboard Piezo buzzer
CPColorLightExternal
Adapts CPColorMatch to light an external LED (or fairy light strand) in response to matching the color red
Attach the external LED/fairy light to pin A1
CPColorMatch
Senses color and matches it to the closest color in an array.
When modifying the colors to try to match to, you need to use the:
colorValues for RGB triples
numColors for the length of the array/number of colors
colorNames to hold corresponding color names
CPColorSpeak
Adapts the Color match to sense red, green and yellow (or no match)
Speaks "The color is red/green/yellow" upon finding a matching color.
CPDFMiniMp3
Works with DF Mini module to play MP3s [BBC sound effects]
Must use CP's dedicated TX and RX pins
(see UnoDFMiniMp3 if using a different board, like an Uno)
CPLightSensor
Turns an external LED on when there is low light
CPMicroServoSweep
Controls an external microservo
CPPianoNotes
Upon turning on, plays a scale of notes
CPSoundBeatsLights
All onboard neopixels turn on in response to (loud) sounds
CPsoundLED
Onboard neopixels turn on in response to sounds - more lights with louder sounds
ExternalSwitch
Onboard LED lights when external circuit switch is closed
UnoDFMiniMp3
Works with DF Mini module to play MP3s [BBC sound effects]
Uses the SoftwareSerial library (available for Uno, not available for CP) to use digital pins for TX and RX
(see CPDFMiniMp3 if using a Circuit Playground)
The Circuit Playground has pins that you can program and attach to external components.
An LED requires the long (positive) leg to be attached to a positive power source, and the short (negative) leg to be attached to negative to complete the circuit.
On the Circuit Playground, we can control digital pins connecting to the positive power source of the board; there are pins for ground (GND) that are always connected to the "negative" for completing circuits.
To wire the Circuit Playground with an external LED, we will connect
the long (positive) leg to a digital pin
many of the pins on an Arduino can controlled as a digital or analog pin, so they end up having dual names
in the sample sketch, we'll use digital pin 3, which is also analog pin A4 (and that is the the label you'll see on the physical board)
the short (negative) leg to a ground GND pin
Sample sketch
Adapt the Sample Blink code to use one of the external pins. Here, we'll use the digital pin 3 (labeled A4 for Analaog 4), referring to the diagram from the board.
/*
Adapted from Examples -> Basics -> Blink
Turns an LED on for one second, then off for one second, repeatedly.
*/
int LED_PIN = 3; // choose to control (digital) pin 3
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_PIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_PIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Here's an example for how to use a paper circuit with the CP -- you can use alligator clips to connect to the copper tape.
To make a better connection for the LED onto the paper circuit:
Use needle nose pliers to curl the LED leads.
Be sure you know which one is positive and which is negative!
Then, rest the LED on copper tape and use a small piece to "sandwich" the curled leads and make a decent connection.
Here's another example that shows how to connect two LEDs (in parallel).
The CP can detect when an external circuit is closed. You can use anything conductive as a "switch" between the open and closed state. The video shows alligator clips, but copper tape, conductive thread, etc. would all work!
Sample sketch
/**
* This code demos how to detect if an external circuit is closed,
* for example because a switch is activated.
* Try it out by:
* - connecting one side of the open circuit to GND
* - connecting the other side to digital pin 10 (A3 on the CP)
* When you close the circuit, the built-in LED should turn on.
**/
#define SWITCH_PIN 10 // A3 on the CP
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT );
pinMode(SWITCH_PIN, INPUT_PULLUP); // enable the internal pull-up resistor
}
void loop() {
// read the value of the switch
int switchState = digitalRead(SWITCH_PIN);
// if the switch is activated, the circuit is closed
if (switchState == LOW)
digitalWrite( LED_BUILTIN, HIGH );
// otherwise, the circuit is open
else
digitalWrite( LED_BUILTIN, LOW );
}
The CP can detect capacitive touch -- you can touch the pins (or connect a conductive material to a pin) and the CP can sense it!
You may need to play with the threshold value. If it's too low, then it will be very sensitive; sometimes just attaching an alligator clip will count as a "touch." In this case, use the Serial monitor to determine a better threshold value.
The sample sketch uses the pins for sensing, counter-clockwise from the On LED.:
Digital pin 3, labeled SCL/A4 on the board
Digital pin 2, labeled SDA/A5 on the board
Digital pin 0, labeled RX/A6 on the board
Digital pin 1, labeled TX on the board
Digital pin 6, labeled A1 on the board
Digital pin 9, labeled A2 on the board
Ditial pin 10, labeled A3 on the board
Sample sketch 1 [touch for lights]
// 7 capacitive touch sensors: A1 - A7
#include <Adafruit_CircuitPlayground.h>
// we light one pixel at a time, this is our counter
uint8_t pixeln = 0;
int capSensorPins[] = { 3, 2, 0, 1, 6, 9, 10 };
int numCapSensors = 7;
int ledForCap[] = { 0, 1, 3, 4, 6, 8, 9 };
// { 3, 2, 0, 1, 6, 9, 10}
// { A4, A5, A6, A7, A1, A2, A3}
// 3 -> A4, 2 -> A5, 0
int THRESHOLD = 1000;
void setup() {
Serial.begin(9600);
CircuitPlayground.begin();
}
void loop() {
// for each pin that could be a capacitive touch sensor
for (int i = 0; i < numCapSensors; i++)
{
// print the information about what we are sensing
Serial.print("Capsense #");
Serial.print(capSensorPins[i]);
Serial.print(": ");
Serial.println(CircuitPlayground.readCap(capSensorPins[i]));
// if the value we sense is large enough
if (CircuitPlayground.readCap(capSensorPins[i]) > THRESHOLD)
// light the associated neopixel
CircuitPlayground.setPixelColor(ledForCap[i], CircuitPlayground.colorWheel(25 * i));
else
// otherwise, clear out the light for that neopixel
CircuitPlayground.setPixelColor(ledForCap[i], 0, 0, 0);
}
delay(50);
}
Sample sketch 2 [touch for lights, A4 for sound]
// 7 capacitive touch sensors: A1 - A7
#include <Adafruit_CircuitPlayground.h>
#define NOTE_G3 196
// we light one pixel at a time, this is our counter
uint8_t pixeln = 0;
int capSensorPins[] = { 3, 2, 0, 1, 6, 9, 10 };
int numCapSensors = 7;
int ledForCap[] = { 0, 1, 3, 4, 6, 8, 9 };
// { 3, 2, 0, 1, 6, 9, 10}
// { A4, A5, A6, A7, A1, A2, A3}
// 3 -> A4, 2 -> A5, 0
int THRESHOLD = 1000;
void setup() {
Serial.begin(9600);
CircuitPlayground.begin();
}
void loop() {
// for each pin that could be a capacitive touch sensor
for (int i = 0; i < numCapSensors; i++)
{
// print the information about what we are sensing
Serial.print("Capsense #");
Serial.print(capSensorPins[i]);
Serial.print(": ");
Serial.println(CircuitPlayground.readCap(capSensorPins[i]));
// if the value we sense is large enough
if (CircuitPlayground.readCap(capSensorPins[i]) > THRESHOLD)
// light the associated neopixel
CircuitPlayground.setPixelColor(ledForCap[i], CircuitPlayground.colorWheel(25 * i));
else
// otherwise, clear out the light for that neopixel
CircuitPlayground.setPixelColor(ledForCap[i], 0, 0, 0);
}
// let's also play a note for one of them, as an example
// we'll pick pin 3, which is labeled SCL/A4 on the board
// if the value is large enough
if ( CircuitPlayground.readCap( 3 ) > THRESHOLD)
// play the note (only if the slide switch is on)
playNote( NOTE_G3, 250 );
delay(50);
}
// Play a note of the specified frequency and for the specified duration.
// No tones will play if the slide switch is in the -/off position.
void playNote(int frequency, int duration) {
// Check if the slide switch is off
if (!CircuitPlayground.slideSwitch()) {
// stop immediately without playing anything.
return;
} else {
// Play the note for the specified duration.
CircuitPlayground.playTone(frequency, duration, false);
// wait for the note to play
delay(duration + duration / 16);
}
}
Micro Servo 9g SG90 (in Elegoo kits)
Load the CPESweep code onto the CPE.
Unplug EVERYTHING!
Attach your wires from the Servo to the CPE:
GND to GND (brown in the image)
Voltage to 3.3V (red in the image)
PWM control to A1 (orange in the image)
Double-check your connections and make sure no metal is touching other metal that you don't want!
Plug in the CPE to power (via USB or external battery)
You should see the motor sweep back and forth now!
#include <Adafruit_CircuitPlayground.h>
#define LED_PIN 10 // labeled A2 on CP board, attach external LED here
#define TOUCH_PIN 3 // labeled A4 on CP board, attach external capacitive touch here
int CAP_THRESHOLD = 1000;
void setup() {
Serial.begin(9600);
CircuitPlayground.begin();
pinMode( LED_PIN, OUTPUT );
}
void loop() {
Serial.print("Cap pin: " );
Serial.println( CircuitPlayground.readCap( TOUCH_PIN ) );
// if there is capacitive touch
if ( CircuitPlayground.readCap( TOUCH_PIN ) > CAP_THRESHOLD )
{
// turn on the LED
digitalWrite( LED_PIN, HIGH );
}
else // otherwise, turn off the LED
{
digitalWrite( LED_PIN, LOW );
}
delay(100);
}
#include <Adafruit_CircuitPlayground.h>
float tempC, tempF;
float mid = 72.0;
float high = 75.0;
void setup() {
Serial.begin(9600);
CircuitPlayground.begin();
}
void loop() {
tempC = CircuitPlayground.temperature();
tempF = CircuitPlayground.temperatureF();
Serial.print("tempC: ");
Serial.print(tempC);
Serial.print(" tempF: ");
Serial.println(tempF);
if ( tempF < mid )
lightNeopixels( 0, 0, 255 );
else if ( tempF < high )
lightNeopixels( 0, 255, 0 );
else
lightNeopixels( 255, 0, 0 );
delay(1000);
}
void lightNeopixels( int r, int g, int b )
{
for ( int i = 0; i < 10; i++ )
CircuitPlayground.setPixelColor( i, r, g, b );
}
Maybe you put some code that works with an external LED and it's not lighting. Or maybe you have code that worked elsewhere and has stopped working with your current sketch...
Things to try:
Make sure you put this line of:
CircuitPlayground.begin();
BEFORE any other code (except maybe Serial.begin) in the setup function.
Don't use variables for the constants (named with all capitals); use #defines, as in:
#define LED_PIN 10 // labeled A2 on CP board
I have no idea why this makes the board mad, and I'm also not sure if it's specific to the CP Bluefruit :(
My theory is: the BlueFruit has very little memory, so perhaps capital letters take up more space...?
It seems the battery can change the values sensed for capacitive touch. You can use this code, which identifies different threshold values for computer/battery power.
Make sure not to touch pin A4 when powering up the board!
// 7 capacitive touch sensors: A1 - A7
#include <Adafruit_CircuitPlayground.h>
// we light one pixel at a time, this is our counter
uint8_t pixeln = 0;
int capSensorPins[] = { 3, 2, 0, 1, 6, 9, 10 };
int numCapSensors = 7;
int ledForCap[] = { 0, 1, 3, 4, 6, 8, 9 };
// { 3, 2, 0, 1, 6, 9, 10}
// { A4, A5, A6, A7, A1, A2, A3}
// 3 -> A4, 2 -> A5, 0
int threshold;
int COMPUTER_THRESH = 800;
int BATTERY_THRESH = 200;
void setup() {
Serial.begin(9600);
CircuitPlayground.begin();
delay( 500 );
// set the threshold to be 100 above the current value
// assumes no capacitive touch when the board is powered up
threshold = CircuitPlayground.readCap( 3 )*1.5;
}
void loop() {
// for each pin that could be a capacitive touch sensor
for (int i = 0; i < numCapSensors; i++)
{
// print the information about what we are sensing
Serial.print("Capsense #");
Serial.print(capSensorPins[i]);
Serial.print(": ");
Serial.println(CircuitPlayground.readCap(capSensorPins[i]));
// if the value we sense is large enough
if (CircuitPlayground.readCap(capSensorPins[i]) > threshold)
// light the associated neopixel
CircuitPlayground.setPixelColor(ledForCap[i], CircuitPlayground.colorWheel(25 * i));
else
// otherwise, clear out the light for that neopixel
CircuitPlayground.setPixelColor(ledForCap[i], 0, 0, 0);
}
delay(50);
}