Analog Team 23
We are Analog Team 23 and we developed a memory-based sequence game using the Circuit Playground that combines visual cues with analog and digital inputs. The game begins by flashing one of three colors, each representing a specific action the player must perform. For example, yellow corresponds to turning the potentiometer knob, while blue requires pressing a button. With each successful round, the game adds another color to the sequence, increasing the difficulty and requiring the player to remember and repeat the entire pattern in order.
If the player correctly completes the sequence, the board flashes green to indicate success and advances to the next round. If a mistake is made, such as turning the potentiometer too far, which may register as multiple inputs the board flashes red and the game resets. This highlights how sensitive analog components can be and how precise input control affects gameplay.
This project demonstrates how analog sensors and programmed feedback can be combined to create an engaging, progressively challenging interactive experience.
Code:
#include <Adafruit_CircuitPlayground.h>
//Defining playground analog inputs
const byte potPin = A2;
const byte buttonPin = A3;
// Game loop variables
int sequence[50]; // stores the pattern
int roundLength = 0; // how many steps this round
void setup() {
CircuitPlayground.begin();
pinMode(buttonPin, INPUT_PULLUP);
//Random seed so the pattern changes every time the playground boots up
randomSeed(analogRead(A1));
roundLength = 1;
sequence[0] = random(0, 3);
}
void loop() {
delay(400);
// Showing the sequence first
for (int i = 0; i < roundLength; i++) {
// Light up pixels for the current step
if (sequence[i] == 0) {
// BLUE = button
for (int p = 0; p < 10; p++) CircuitPlayground.setPixelColor(p, 0, 0, 255);
}
else if (sequence[i] == 1) {
// YELLOW = pot
for (int p = 0; p < 10; p++) CircuitPlayground.setPixelColor(p, 255, 255, 0);
}
else {
// WHITE = tilt
for (int p = 0; p < 10; p++) CircuitPlayground.setPixelColor(p, 255, 255, 255);
}
delay(500);
CircuitPlayground.clearPixels();
delay(250);
}
// Listening for player inputs
// Setting baselines
int potStart = analogRead(potPin);
bool tiltNeedsCenter = false; // boolean to make sure that the board returns to center before tilt input can be used again (prevents multiple fires)
for (int i = 0; i < roundLength; i++) {
int expected = sequence[i];
int playerAction = -1;
// Wait until the player does ONE action
while (playerAction == -1) {
// Check for button press
if (digitalRead(buttonPin) == LOW) {
playerAction = 0;
delay(200);
}
// Check for potentiometer input
int potNow = analogRead(potPin);
if (abs(potNow - potStart) > 80) {
playerAction = 1;
potStart = potNow; // update baseline
delay(200);
}
// Check for tilt
float x = CircuitPlayground.motionX();
float tiltAmount = abs(x); // Ignores tilt direction
if (tiltAmount > 8) {
tiltAmount = 8;
}
// Mapping tilts to make the player tilt the playground farther in order to get a tilt input
int tiltLevel = map((int)(tiltAmount * 100), 0, 800, 0, 100);
float tiltCurve = (tiltLevel / 100);
tiltCurve = tiltCurve * tiltCurve;
int finalTiltValue = tiltCurve * 100;
if (tiltAmount < 1) { // Checks if playground is not tilted
tiltNeedsCenter = false;
}
if (!tiltNeedsCenter && finalTiltValue > 40) {
playerAction = 2;
tiltNeedsCenter = true; // must re-center before next tilt
delay(200);
}
}
// Giving player feedback for actions
// Light up pixels to show what the player just did
if (playerAction == 0) {
for (int p = 0; p < 10; p++) CircuitPlayground.setPixelColor(p, 0, 0, 255);
}
else if (playerAction == 1) {
for (int p = 0; p < 10; p++) CircuitPlayground.setPixelColor(p, 255, 255, 0);
}
else if (playerAction == 2) {
for (int p = 0; p < 10; p++) CircuitPlayground.setPixelColor(p, 255, 255, 255);
}
// How long the feedback shows before getting cleared
delay(300);
CircuitPlayground.clearPixels();
// Compare player input to expected
if (playerAction != expected) {
// FAIL = flash red and restart
for (int t = 0; t < 3; t++) {
for (int p = 0; p < 10; p++) CircuitPlayground.setPixelColor(p, 255, 0, 0);
delay(200);
CircuitPlayground.clearPixels();
delay(200);
}
// restart the game
roundLength = 1;
sequence[0] = random(0, 3);
return; // exit loop() early and start over
}
}
// Handles player success
for (int t = 0; t < 3; t++) {
for (int p = 0; p < 10; p++) CircuitPlayground.setPixelColor(p, 0, 255, 0);
delay(200);
CircuitPlayground.clearPixels();
delay(200);
}
// Add one more step to the pattern for the next round
if (roundLength < 50) {
sequence[roundLength] = random(0, 3);
roundLength++;
}
delay(300);
}

