26 April 2026

Team 12- Game Controller

 


Our controller’s shape and overall design is based on the Type-A fighter which acts as a boss in ZeroRanger. This ship is the same type as those used by the player. To control their up and down movement the player tilts the controller forwards and back, this movement is tracked by the accelerometer on the Circuit Playground. To move left and right the player turns the potentiometer in the direction they want to move. The player’s three fire inputs are controlled by light sensors. When the sliding panel above the sensor is moved, it is revealed to the light and inputs the corresponding fire command in game. Fire 1 acts as the select button in menus while fire 2 is the back button. Lastly by moving the switch the player can transform their ship into melee mode then flip the switch back to return to the standard ship. The sections of the controller used to input are colored in orange, allowing players to find them easily and know which parts of the controller will move. The three light sensors are also placed roughly where that weapon will fire from in the game. Alongside the game’s audio and visual feedback the controller provides physical feedback with each input resulting in a motion on the controller. The controller also provides additional visual feedback with the player able to see the revealed light sensor or use the marks on the potentiometer to tell its current position.

Question: How could the design better allow the player to input different actions in quick succession?


Schematic- 


Code-

 #include <Adafruit_CircuitPlayground.h>

#include <Adafruit_Circuit_Playground.h>

#include "Keyboard.h"

 

//define variables for initial light values

int ZeroRead;

int TwoRead;

int ThreeRead;

 

void setup() {

Serial.begin(9600);

CircuitPlayground.begin();

Keyboard.begin();

delay(1000);

//set initial light values

int ZeroRead = analogRead(A0);

int TwoRead = analogRead(A2);

int ThreeRead = analogRead(A3);

}

 

//define variables for controlling release of fire buttons

bool fire1 = 0;

bool fire2 = 0;

bool fire3 = 0;

 

//define variables for controlling transform macro

bool oldform = 0;

bool newform = 1;

 

void loop() {

//Only read inputs if CircuitPlayground switch is set to on position

if (CircuitPlayground.slideSwitch() < 1) {

//Press Z(fire1) while light sensor 1 is uncovered and release it when it is covered

  if (analogRead(A2) > TwoRead + 20) {

    Keyboard.press('z');

    fire1 = 1;

  }

  if (fire1 == 1) {

  if (analogRead(A2) <= TwoRead + 20) {

     Keyboard.release('z');

     fire1 = 0;

     }

  }

//Press X(fire2) while light sensor 2 is uncovered and release it when it is covered

  if (analogRead(A0) < (ZeroRead + 20)) {

    Keyboard.press('x');

    fire2 = 1;

  }

  if (fire2 == 1) {

  if (analogRead(A0) >= (ZeroRead + 20)) {

     Keyboard.release('x');

     fire2 = 0;

     }

  }

//Press C(fire3) while light sensor 3 is uncovered and release it when it is covered

  if (analogRead(A3) < (ThreeRead + 20)) {

    Keyboard.press('c');

    fire3 = 1;

  }

  if (fire3 == 1) {

   if (analogRead(A3) > (ThreeRead + 20)) {

     Keyboard.release('c');

     fire3 = 0;

     }

  }

//Write Left Ctrl(fire1+2+3 macro) when the switch changes position

  if (oldform != newform) {

   if (analogRead(A7) > 1000 ) {

     Keyboard.write(KEY_LEFT_CTRL);

     newform = 0;

  }

  }

  if (oldform == newform) {

    if (analogRead(A7) < 50) {

      Keyboard.write(KEY_LEFT_CTRL);

      newform = 1;

    }

  }

//Move up and down based on accelerometer value

 if (CircuitPlayground.motionY() <= -2) {

  Keyboard.press(KEY_UP_ARROW);

 }

if (CircuitPlayground.motionY() > -2) {

  Keyboard.release(KEY_UP_ARROW);

  }

 if (CircuitPlayground.motionY() >= 2) {

  Keyboard.press(KEY_DOWN_ARROW);

 }

if (CircuitPlayground.motionY() < 2) {

  Keyboard.release(KEY_DOWN_ARROW);

  }

//Move left or right based on potentiometer value

 if (analogRead(A6) <= 400) {

  Keyboard.press(KEY_RIGHT_ARROW);

 }

if (analogRead(A6) > 400) {

  Keyboard.release(KEY_RIGHT_ARROW);

  }

 if (analogRead(A6) >= 700) {

  Keyboard.press(KEY_LEFT_ARROW);

 }

if (analogRead(A6) < 700) {

  Keyboard.release(KEY_LEFT_ARROW);

  }

}

}

Video-

(Due to sudden mechanical failures our controller was not functional to record the video)



 



No comments:

Post a Comment

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