01 March 2026

Mapping Assignment - Analog Team 1

When starting our game, you will notice a solid blue and blinking green light. The blue light is the player character, and the green light represents your goal. By rotating the potentiometer, you can move the blue pixel around the circuit playground to traverse the stage. The goal is hard to see during the day, causing it to blink less frequently, so players must turn the stage to night by covering the circuit playground to make the goal light remain green. Once the blue light and green light overlap, press the button on the breadboard to confirm your position, winning the game!

Video Demonstration: https://www.youtube.com/watch?v=VPvlQegVsFE

Code:

#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>

//Analog Team 1 David Diaz & Ethan Hogan
int show;
int goal;
bool flag = true;

//should adjust the lights for the light sensor
int minVal = 1023;
int maxVal = 0;

void setup() {
  // Sets up the Circuit Playground and the Light sensor on the board:
  Serial.begin(9600);
  CircuitPlayground.begin();
  delay(1000);
  randomSeed(CircuitPlayground.lightSensor());
}

void loop() {
  // put your main code here, to run repeatedly:
  int value = analogRead(A2);
  int mapped = map(value, 0, 1023, 0, 10);
 
  //potentiometer is main control, use to move your active blue light onto the green light
  CircuitPlayground.clearPixels();
  CircuitPlayground.setPixelColor(mapped, 0, 0, 255);
  delay(10);

  //set goal
  if(flag == true) {
  goal = random(9);
  flag = false;
  }
 
  //Goal light flickers rapidly at neutral light values, darker light from covering the sensor slows down the flickering
  show = CircuitPlayground.lightSensor();
  Serial.println(show);
  if(show <= 40) {
    CircuitPlayground.setPixelColor(goal, 0, 255, 0);
  }


  //Button Check for if you pressed on the goal light or not. high notes for correct placement, low notes for incorrect placement
  int button = analogRead(A3);
  if(mapped == goal && button > 512) {
    flag = true;
    CircuitPlayground.playTone(950,100);
    delay(50);
    CircuitPlayground.playTone(950,100);
    delay(50);
    CircuitPlayground.playTone(1100,100);
  } else if(button > 512){
    for (int i=0; i < 10; i=i+1){
      CircuitPlayground.setPixelColor(i, 255, 0, 0);
    }
    CircuitPlayground.playTone(200,50);
    delay(20);
    CircuitPlayground.playTone(200,50);
    delay(20);
    CircuitPlayground.playTone(100,300);
    delay(1000);
    flag = true;
  }
 
}





No comments:

Post a Comment

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