01 March 2026

Mapping Assignment - Analog Team 9

Game Description:

Our game’s concept is to recreate the fishing experience through an arcade-like game where the player must seek out where the fish is located in under 60 seconds. The game is started by clicking the button to "cast the line". The player will then use the potentiometer similar to a fishing reel with the Circuit Playground’s NeoPixels being used as a guide on where the fish is located compared to the player’s “Bobber”. If the player finds a fish, they must quickly reel it in by physically pulling the Circuit Playground up. If the player manages to catch the fish, the timer will be reset and the difficulty will go up by having the size of the range the fish is in increase and a quicker time limit and then they will press the button again to play the harder mode. If the player doesn’t catch the fish, then the difficulty will go down but the timer will continue. If the player runs out of time, the game will end and they will have to click the button again to retry.

Video Demonstration:


(Due to an issue with uploading to the circuit playground, the video does not show the functionality of the NeoPixel display.)

Code:

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

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
CircuitPlayground.begin();
delay(1000);
}

void loop() {

//define base timer amount
int timermax = 60;

//define range base minimum and maximum
int rlow = 1;
int rhigh = 100;

//define success variable
bool victory = false;
bool capture = true;

//define variable to be mapped as A2
int A2m = A2;

//button press generates random value and begins timer
if (A3 > 1000 && capture == true) {
 int fish = random(rlow, rhigh);
 victory = false;
 capture = false;

 //map potentiometer values to range
 A2m = map(A2m, 0, 1023, rlow, rhigh);

 for (int i = 0; i <= timermax; i++){
  //potentiometer reading indicates if the player is left, right, or on top of the fish
   //IF potentiometer is low light up left
  if (A2m < fish) {
    //Player fails if capture attempted
    victory = false;
    //Light up Left side
    CircuitPlayground.setPixelColor(0, 0, 0, 255);
    CircuitPlayground.setPixelColor(1, 0, 0, 255);
    CircuitPlayground.setPixelColor(2, 0, 0, 255);
    CircuitPlayground.setPixelColor(3, 0, 0, 255);
    CircuitPlayground.setPixelColor(4, 0, 0, 255);
    CircuitPlayground.setPixelColor(5, 0, 0, 255);
    CircuitPlayground.setPixelColor(6, 0, 0, 255);
    CircuitPlayground.setPixelColor(7, 0, 0, 255);
    CircuitPlayground.setPixelColor(8, 255, 255, 0);
    CircuitPlayground.setPixelColor(9, 255, 255, 0);
  }
   //IF potentiometer is high light up right
  if (A2m > fish) {
    //Player fails if capture attempted
    victory = false;
    //Light up Right side
    CircuitPlayground.setPixelColor(0, 255, 255, 0);
    CircuitPlayground.setPixelColor(1, 255, 255, 0);
    CircuitPlayground.setPixelColor(2, 0, 0, 255);
    CircuitPlayground.setPixelColor(3, 0, 0, 255);
    CircuitPlayground.setPixelColor(4, 0, 0, 255);
    CircuitPlayground.setPixelColor(5, 0, 0, 255);
    CircuitPlayground.setPixelColor(6, 0, 0, 255);
    CircuitPlayground.setPixelColor(7, 0, 0, 255);
    CircuitPlayground.setPixelColor(8, 0, 0, 255);
    CircuitPlayground.setPixelColor(9, 0, 0, 255);
  }
   //IF potentiometer equals light up both and make success true
  if (A2m > fish) {
    //Allow player to catch fish
    victory = true;
    //Light up Both sides
    CircuitPlayground.setPixelColor(0, 255, 255, 0);
    CircuitPlayground.setPixelColor(1, 255, 255, 0);
    CircuitPlayground.setPixelColor(2, 0, 0, 255);
    CircuitPlayground.setPixelColor(3, 0, 0, 255);
    CircuitPlayground.setPixelColor(4, 0, 0, 255);
    CircuitPlayground.setPixelColor(5, 0, 0, 255);
    CircuitPlayground.setPixelColor(6, 0, 0, 255);
    CircuitPlayground.setPixelColor(7, 0, 0, 255);
    CircuitPlayground.setPixelColor(8, 255, 255, 0);
    CircuitPlayground.setPixelColor(9, 255, 255, 0);
  }
  //accelerometer detects motion and provides feedback for a success or failure
    if (CircuitPlayground.motionZ() > 10) {
      //confirm that capture was attempted
     capture = true;
      //IF success equals true then light up green and increase difficulty
     if (victory == true) {
      //increase difficulty
      timermax -= 5;
      rlow = 1;
      rhigh += 10;
      //set timer variable to allow for next button press
      i = timermax;
      // Light up Green
      CircuitPlayground.setPixelColor(0, 0, 255, 0);
      CircuitPlayground.setPixelColor(1, 0, 255, 0);
      CircuitPlayground.setPixelColor(2, 0, 255, 0);
      CircuitPlayground.setPixelColor(3, 0, 255, 0);
      CircuitPlayground.setPixelColor(4, 0, 255, 0);
      CircuitPlayground.setPixelColor(5, 0, 255, 0);
      CircuitPlayground.setPixelColor(6, 0, 255, 0);
      CircuitPlayground.setPixelColor(7, 0, 255, 0);
      CircuitPlayground.setPixelColor(8, 0, 255, 0);
      CircuitPlayground.setPixelColor(9, 0, 255, 0);
      delay(10);
      CircuitPlayground.clearPixels();
     }
      //IF success does not equal true then light up red and reset difficulty
     if (victory == false) {
      //confirm that capture was attempted
      capture = true;
      //reset difficulty variables
      timermax = 60;
      rlow = 1;
      rhigh = 100;
      //set timer variable to allow for next button press
      i = timermax;
      //Light up Red
      CircuitPlayground.setPixelColor(0, 255, 0, 0);
      CircuitPlayground.setPixelColor(1, 255, 0, 0);
      CircuitPlayground.setPixelColor(2, 255, 0, 0);
      CircuitPlayground.setPixelColor(3, 255, 0, 0);
      CircuitPlayground.setPixelColor(4, 255, 0, 0);
      CircuitPlayground.setPixelColor(5, 255, 0, 0);
      CircuitPlayground.setPixelColor(6, 255, 0, 0);
      CircuitPlayground.setPixelColor(7, 255, 0, 0);
      CircuitPlayground.setPixelColor(8, 255, 0, 0);
      CircuitPlayground.setPixelColor(9, 255, 0, 0);
      delay(10);
      CircuitPlayground.clearPixels();
     }
  }

  //IF timer run out fail if no catch attempted
  if (i == timermax) {
    if (capture == false) {
      i = 0;
      //reset difficulty variables
      timermax = 60;
      rlow = 1;
      rhigh += 10;
      //set timer variable and change capture variable to allow for next button press
      i = timermax;
      capture = true;
    }
  }

 delay(10);
}
}
}

Schematic Drawing:



No comments:

Post a Comment

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