01 March 2026

Scaffolding: Mapping - Light in the Dark

    This game is a fast‑paced, breadboard‑based challenge that tests precision, timing, and awareness. Using a potentiometer, the player controls a red LED that moves across the playing field. The objective is to locate the hidden green LED “goal,” which only becomes visible when the light sensor is covered. Once the player identifies the correct position, they must press the button to advance to the next level. However, accuracy is critical pressing the button when the red light is not on the goal immediately ends the game. The challenge is to see how many levels you can clear in the shortest time possible, creating a tense balance between speed and careful control. The button uses a pull‑down resistor configuration, with the resistor connected to ground and the button tied to the positive rail, ensuring clean and reliable input detection during gameplay.





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

bool flag = true;
int goal;
int show;

void setup() {
  // put your setup code here, to run once:
  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 light
  CircuitPlayground.clearPixels();
  CircuitPlayground.setPixelColor(mapped, 255, 0, 0);
  delay(10);

  //set goal
  if(flag == true) {
  goal = random(9);
  flag = false;
  }
  
  //show goal through light sensor
  show = CircuitPlayground.lightSensor();
  Serial.println(show);
  if(show <= 70) {
    CircuitPlayground.setPixelColor(goal, 0, 255, 0);
  }


  //check if button pressed on goal or fail
  int button = analogRead(A3);
  if(mapped == goal && button > 512) {
    flag = true;
    CircuitPlayground.playTone(500,100);
  } else if(button > 512){
    for (int i=0; i < 10; i=i+1){
      CircuitPlayground.setPixelColor(i, 255, 0, 0);
    }
    CircuitPlayground.playTone(100,50);
    delay(10);
    CircuitPlayground.playTone(100,300);
    delay(1000);
    flag = true;
  }
  
}


Melanie Nainstein & Stephen Fink-Mariani


No comments:

Post a Comment

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