01 March 2026

Scaffolding Mapping - Fishing Game

 For our project we made a small interactive fishing game. The red light represents the fish, and other blue light represents the fishing hook. The player uses the potentiometer to move the hook across the board. When the hook lines up with the fish, it will turn purple and the player presses a button to catch it. The goal is for the player to guide the fish back to the starting position without losing it. If a loud noise is made, the fish will get scared and will respawn somewhere else, this adds some challenge and makes the experience feel more realistic.








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

// constants
const char potential = A2;
const char boardButton = A3;
const int hookColor = 000077;

// variables
int fishingHook = 0;
int fishLocation = 0;
bool pressingButton = 0;

void setup() {
  
  Serial.begin(9600);

  Serial.clear();

  randomSeed(analogRead(A0)); // generates random seed for random function using static noise from unused pin

  CircuitPlayground.begin(); // begins playground functions

  CircuitPlayground.setBrightness(255); // sets the brightness of the leds

  SpawnFish();
}

void loop() {
  CircuitPlayground.clearPixels(); // clears all pixels

  ReadFishingHook();
  ReadButton();

  if(fishingHook != 0) {
    CircuitPlayground.setPixelColor(PondToPixel(fishingHook), 00, 00, 255);
  }
  
  CircuitPlayground.setPixelColor(PondToPixel(fishLocation), 255, 00, 00);

  if (fishingHook == fishLocation) {
    CircuitPlayground.playTone(255, 9);
    if (pressingButton) 
      Serial.println("caughtFish");
  }

  // Serial.println(pressingButton);
}

int PondToPixel(int local) {
  if(local < 0) 
    return local + 5;
  if(local > 0) 
    return local + 4;

  return -1;
}

int ReadFishingHook() {
  fishingHook = map(analogRead(potential), 0, 1023, -5, 5);
}

bool ReadButton() {
  int value = map(analogRead(boardButton), 0, 1023, 0, 1);
  pressingButton = !value;
}

void SpawnFish() {
  fishLocation = random(0, 6);
  if(fishLocation <= 2) {
    fishLocation -= 5;
  }
}





No comments:

Post a Comment

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