02 March 2026

Analog Team 22

By: Jesse Smith and Jonathan Tsigas


Our game is themed on solving a combination lock that combines rotating and aligning the Circuit Playground with illuminated LEDs. Each round, a distinct LED will glow, and the player has to move the Circuit Playground to get the "Key" LED to align with the "Lock" LED. Once the player believes the LEDs are aligned, they press the button to set that lock in. That sequence will occur three times, making the player solve three separate lock mechanisms to unlock the complete lock. Once all three locks are solved, the player must shake the Circuit Playground to try to open the lock. If they successfully unlock all three locks, then all the lights will glow green, and they will move onto the next level. If they did not do it correctly, all of the lights will glow red, and they will have to restart the level. 

The switch on the CPE turns the game on and off. 

Demonstration





#include <Adafruit_CircuitPlayground.h> #include <Adafruit_Circuit_Playground.h> const int led = 13; const int slideSwitch = 7; int neoState = 0; int i = 0; int mappedValue = 0; int previousValue = 0; bool showedCombination = false; unsigned long previousTime = 0; int lock1 = 0; int lock2 = 0; int lock3 = 0; const int ButtonPin = A3; bool lockFailed = false; int currentLock = 0; int Locks[3]; int shakeThresh = 25; //const int buttonA = 4; void setup() { // put your setup code here, to run once: pinMode(led, OUTPUT); //pinMode(buttonA, INPUT_PULLDOWN); //pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLUP); Serial.begin(9600); CircuitPlayground.begin(); pinMode(ButtonPin, INPUT); randomSeed(micros()); //pinMode(buttonA, INPUT_PULLUP); delay(2000); } void loop() { // put your main code here, to run repeatedly: //Serial.println("Hi"); // Serial.println(analogRead(A2)); //Serial.println(digitalRead(ButtonPin)); if (showedCombination == false) { showCombination(); } previousValue = mappedValue; i = analogRead(A2); mappedValue = map(i, 0, 1024, 0, 10); // Serial.println(mappedValue); if (previousValue != mappedValue) { CircuitPlayground.setPixelColor(previousValue, 0, 0 , 0); } CircuitPlayground.setPixelColor(mappedValue, 30, 10, 100); if (digitalRead(ButtonPin)) { //Serial.println("Num picked"); if (mappedValue != Locks[currentLock]) { Serial.println("wrong"); lockFailed = true; } else if (mappedValue == Locks[currentLock]) { Serial.println("correct"); } currentLock++; delay(500); } float shake = abs(CircuitPlayground.motionX()) + abs(CircuitPlayground.motionY()) + abs(CircuitPlayground.motionZ()); Serial.println(shake); if (shake > shakeThresh && currentLock == sizeof(Locks) / sizeof(Locks[0])) { if (lockFailed) { for (int b = 0; b <= 9; b++) { CircuitPlayground.setPixelColor(b, 255, 0, 0); } } else if (!lockFailed) { for (int b = 0; b <= 9; b++) { CircuitPlayground.setPixelColor(b, 0, 255, 0); } } } } void showCombination() { for (int y = 0; y < sizeof(Locks) / sizeof(Locks[0]); y++) { Locks[y] = random(10); Serial.println(Locks[y]); CircuitPlayground.setPixelColor(Locks[y], 30, 10, 100); delay(500); CircuitPlayground.setPixelColor(Locks[y], 0, 0, 0); delay(500); showedCombination = true; } }


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.