28 March 2021

Game Controller Progress

 


  The game I am going to play is Dark Souls 3, so I wanted the controller to match the character with a sword and shield. The shield will have the CPE attached and will move WASD with the accelerometer by tilting it around, and the wires will go into the sword which can be touched against an object to trigger an attack and a dodge. The sound sensor will also pick up on my voice so that I can lock onto an enemy with the Q key. 

  Two questions I have with my design is: what do you think is the best way to attach the sword to the CPE with wires, and should I be triggering the attack with a movement or actually touching the sword to a target dummy?


#include <Keyboard.h>

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

const int debounce = 100;
const int threshold = 500;


void setup() {
  // put your setup code here, to run once:
  CircuitPlayground.begin();
  //create pin for switch to turn on and off
  pinMode(CPLAY_SLIDESWITCHPIN, INPUT_PULLUP);
  //create pin for attack
  //create pin for sound lock on
  Keyboard.begin();
  Serial.begin(9600);
 

}

void loop() {
  // put your main code here, to run repeatedly:
  //accelerometer setup
  float x = CircuitPlayground.motionX();
  float y = CircuitPlayground.motionY();
  float z = CircuitPlayground.motionZ();
  //if slideswitch is on:
  if(digitalRead(CPLAY_SLIDESWITCHPIN)) {
    if(CircuitPlayground.readCap(A3) > threshold) {
      Keyboard.write(' ');
      delay(debounce);
      //if attack pin is above threshhold, press right mouse button
    }
    float sound = CircuitPlayground.mic.soundPressureLevel(10);

    if(sound >= 70) {
      Keyboard.write('Q');
      delay(debounce);
      //if sound pin is above threshhold, press Q
    }
    if(z >= 5) {
      Keyboard.write('W');
      delay(debounce);
      //when z accelerometer is in range, press W
    }
    else if(z <= -5) {
      Keyboard.write('S');
      delay(debounce);
      //when z accelerometer is in range, press S
    }
    if(x <= -4) {
      Keyboard.write('A');
      delay(debounce);
      //when x accelerometer is in range,press A
    }
    else if(x >= 4){
      Keyboard.write('D');
      delay(debounce);
      //when x accelerometer is in range, press D
    }
  }
  
  Serial.println(CircuitPlayground.readCap(A3));
  //Serial.println(x);
  //Serial.print("\t");
  //Serial.println(y);
  //Serial.print("\t");
  //Serial.println(z);
  //Serial.print("\t");
  //Serial.println(CircuitPlayground.soundSensor());
}




No comments:

Post a Comment

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