27 November 2023

Pac-Man Final Controller

 

Description:
My our project I created a Pac-Man controller operated by light sensors. The basis of my model is of course inspired by Pac-Man himself built to be in his likeness with the addition of arcade like arrows to inform the player which light sensor will move Pac-Man in what direction, I specifically picked red arrows to make it similar to the ones commonly found on the original arcade machine.. The way this works is that by depriving my light sensors of light by hovering your hand over it Pac-Man will then move up, down, left and right as it is mapped to the arrow keys. I created the control to be played flat since in the game Pac-Man himself is flat on the screen. While Pac-Man is usually played with a joy-con at an arcade I wanted to go against that and make a hands free controller which is why I am using my light sensors. This was also meant to increase the difficulty of the game as most people are used to using their hands for controls while this requires nothing but your shadow to move Pac-Man. My question is do you think I could've improved my layout for the controls and added some more flair to the design or is it good as is?

Schematic:







Code:
#include <Keyboard.h>
#include <KeyboardLayout.h>
//#include <Keyboard_da_DK.h>
//#include <Keyboard_de_DE.h>
//#include <Keyboard_es_ES.h>
//#include <Keyboard_fr_FR.h>
//#include <Keyboard_it_IT.h>
//#include <Keyboard_sv_SE.h>

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

const int debounce = 10;

void setup() {
  // put your setup code here, to run once:
  CircuitPlayground.begin();
 pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP);
 //pinMode(KEY_LEFT_ARROW, INPUT_PULLUP);
 //pinMode(KEY_RIGHT_ARROW, INPUT_PULLUP);
 //pinMode (KEY_UP_ARROW, INPUT_PULLUP);
 //pinMode (KEY_DOWN_ARROW, INPUT_PULLUP);
 Keyboard.begin();
 Serial.begin(9600);
 delay(1000);
}

void loop() {
  // put your main code here, to run repeatedly:
if(digitalRead(CPLAY_SLIDESWITCHPIN)==LOW) { //SAFETY
  int threshold = 1015; //adjust based on lighting
  if(analogRead(A3) > threshold) {
  //If the light sensor connected to A3 reaches the threshold input left key
  Keyboard.write(KEY_LEFT_ARROW);
  }
  if (analogRead(A6) > threshold) {
    //If the light sensor connected to A6 rreaches the threshold input right key
    Keyboard.write(KEY_RIGHT_ARROW);
  }
  if (analogRead(A1) > threshold) {
    //If the light sensor connected to A1 reaches the threshold input up key
    Serial.println("A1");
    Keyboard.write(KEY_UP_ARROW);
    delay(debounce);
  }
  if (analogRead(A4) > threshold) {
    //If the light sensor connected to A4 reaches the threshold input down key
    Keyboard.write(KEY_DOWN_ARROW);
  }
 delay(debounce);
}
Serial.print(digitalRead(CPLAY_SLIDESWITCHPIN));
Serial.print("\t");
Serial.print(analogRead(A4));
Serial.print("\t");
Serial.print(analogRead(A3));
Serial.print("\t");
Serial.print(analogRead(A1));
Serial.print("\t");
Serial.println(analogRead(A6));
}
//For Serial Monitor to check the values of my lightsensors.


Video: 


 


No comments:

Post a Comment

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