17 April 2022

Final Game Controller

 



The concept of this game controller was inspired by the buzz saw trap that is commonly found in the game Bloody Trapland 2. I used a circular saw blade, filing down any sharp edges to avoid any accidental cuts, and attached the Circuit Playground Bluefruit to the back in an enclosed casing, positioning it so that the light sensor is not obstructed by the saw. I did want to do engraving for signifiers; however, due to limitations on time, resources, and my own skill level, I was unable to complete that portion of the design and had to resort to using a marker.

The functionality of the keyboard is simple. Tilting the left down would move the character left, tilting the right down would move the character to the right, and tilting the top up would cause the character to jump. Additionally, tilting the top down would be used to select options in the main menu and covering the center of the device, where the light sensor is located, would cause the character to crouch.

In the video demonstration at the bottom of this blog post you can see the functionality of the controller. It’s sensitive enough to play with one hand but not too sensitive to cause excessive movement once the user is able to understand it’s functionality more.

The goal of this controller was to create an interesting yet unnaturally shaped controller that can be used with either one or both hands, perhaps even used cooperatively amongst friends, but that can add an additional challenge to the game for more experienced players.


What design changes do you think I could have made to the controller to make it easier for a new user to understand and use?


Complete Code

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

//HID report descriptor using TinUSB's template
//Single report (no ID) descriptor
uint8_t const desc_hid_report[] =
{
  TUD_HID_REPORT_DESC_KEYBOARD()
};

//USB HID object. For the ESP32 these values cannot be changed after declaration
//desc report, desc lens, protocol, interval, use out endpoint
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_KEYBOARD, 2, false);
//https://github.com/hathach/tinyusb/blob/master/src/class/hid/hid.h

const int debounce = 100;
const int thresh = 500;
int light;



void setup() {
  // put your setup code here, to run once:
  CircuitPlayground.begin();
  //pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLDOWN);
  //pinMode(CPLAY_LEFTBUTTON, INPUT_PULLDOWN);
  //pinMode(CPLAY_RIGHTBUTTON, INPUT_PULLDOWN);
  Serial.begin(9600);
  usb_hid.begin();
  
}

void loop() {
  // put your main code here, to run repeatedly:

  //running keyboard report components
  uint8_t const report_id = 0; //unsigned 8bit (1byte) int
  uint8_t const modifier = 0; //used by libraries to save space
  uint8_t keycode[6] = {0}; //normal int is 16 bit (4 bytes)

  //inputs
  float X = CircuitPlayground.motionX(); //tilt to move left right (A & D keys)
  float Y = CircuitPlayground.motionY(); //tilt up to jump (W key)
  light = analogRead(A8); //cover light sensor to crouch (S key)

  //Serial.print(light);
  //Serial.println("\t");


  //moving right
  if(X <= -3){
        keycode[0]= 0x07;//D key
        usb_hid.keyboardReport(report_id, modifier, keycode);
        //Serial.print(X);
        //Serial.print("\t");
        //sSerial.println("D Key pressed");
        delay(debounce);
        usb_hid.keyboardRelease(0);
  }

  //moving left
  if(X >= 3 ){
        keycode[0]= 0x04;//A key
        usb_hid.keyboardReport(report_id, modifier, keycode);
        //Serial.print(X);
        //Serial.print("\t");
        //Serial.println("A Key pressed");
        delay(debounce);
        usb_hid.keyboardRelease(0);
  }
  
  //jumping
  if(Y >= 3 ){
        keycode[0]= 0x1A;//W key
        usb_hid.keyboardReport(report_id, modifier, keycode);
        //Serial.print(Y);
        //Serial.print("\t");
        //Serial.println("W Key pressed");
        delay(debounce);
        usb_hid.keyboardRelease(0);
  }
    //crouching
  if(light <= 3 ){
        keycode[0]= 0x16;//S key
        usb_hid.keyboardReport(report_id, modifier, keycode);
        //Serial.print(light);
        //Serial.print("\t");
        //Serial.println("S Key pressed");
        delay(debounce);
        usb_hid.keyboardRelease(0);
  }

  //enter key
  if (Y <= -3){
        keycode[0]= 0x28;//W key
        usb_hid.keyboardReport(report_id, modifier, keycode);
        //Serial.print(Y);
        //Serial.print("\t");
        //Serial.println("Enter Key pressed");
        delay(debounce);
        usb_hid.keyboardRelease(0);
  }
  
}





No comments:

Post a Comment

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