The game that I am going to be creating a controller for is Crypt of the Necrodancer, which is a rhythm, action adventure game which uses the arrow keys as well as combinations of arrow keys in order to move and attack within a grid-based dungeon.
My controller will be a modified glove that will have the Circuit Playground Express(CPE) attached to the back of the hand as well as four pressure sensors at the tips of the fingers. The controls use a combination of the internal gyroscope of the CPE and the pressure sensors on the finger tips to register the arrow keys of the keyboard.
Rough Sketch:
My thoughts on the glove would be that all the major wiring would be attached to an internal glove, I have a 3D printed base that I plan to hot glue down onto the base glove, but the wires would be supported either sewn loops or Velcro. In order to cover the internal wiring, I had planned to have a secondary extra large glove so that the wiring is protected, but not so tight that the wires come apart, with an easy way to access the glove without disrupting too much of the wires in case a fix is in order.
Schematics:
Video:
Questions:
As stated earlier, I was thinking of using Velcro or sewn loop in order to keep the wiring in place, but do you believe their could be a better way of doing this, especially with the force resistors? maybe those rubber sticky dots for the sensors?
Also, would it be better if I had made a custom sewn glove of the outer glove or would it be better to get and extra large glove and make modifications? Does where the cut on the outer glove make sense or is there a possible better cut I could make?
Pseudo Code:
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
#include <Keyboard.h>
//Constants========================
const int debounce = 200;
const int threshold = 4;
//Variables=======================
//returned to neutral state--------------------------------------
bool gyroReturn=1;
bool touchReturn1=1;
bool touchReturn2=1;
bool touchReturn3=1;
bool touchReturn4=1;
//analog reads----------------------------------------------------
int touchPin1= 1; // the FSR and 10K pulldown are connected to a1
int touchPin2 = 2; // the FSR and 10K pulldown are connected to a2
int touchPin3 = 3; // the FSR and 10K pulldown are connected to a3
int touchPin4 = 4; // the FSR and 10K pulldown are connected to a4
// the analog reading from the FSR resistor divider--------------
int touch1;
int touch2;
int touch3;
int touch4;
//Setup============================================
void setup() {
Serial.begin(9600);
CircuitPlayground.begin();
Keyboard.begin();
}
//Loop============================================
void loop() {
//Gyroscope==============================================
//read accelerometer x and y
float x = CircuitPlayground.motionX();
float y = CircuitPlayground.motionY();
float z = CircuitPlayground.motionZ(); //going to need to be mapped any:any
Serial.print (x);
Serial.print ("\t");
Serial.println(y);
Serial.print ("\t");
Serial.println(z);
//threshold for button presses on gyro is 4 or 5
//negative x left
if (x < -threshold && gyroReturn == 1){
gyroReturn = 0;
Keyboard.write(216);
delay(debounce);
Serial.println("Left");
}
//positive x right
else if (x > threshold && gyroReturn == 1){
gyroReturn = 0;
Keyboard.write(215);
delay(debounce);
Serial.println("Right");
}
//negative y up
else if (y < -threshold && gyroReturn == 1){
gyroReturn = 0;
Keyboard.write(218);
delay(debounce);
Serial.println("Up");
}
//positive y Down
else if (y > threshold && gyroReturn == 1){
gyroReturn = 0;
Keyboard.write(217);
delay(debounce);
Serial.println("Down");
}
else{
gyroReturn = 1;
Serial.println("Neutral");
}
// 2 Combo arrows--------------------------------------------------
/* if neg x && pos y
left down buttons pressedelse return to neutral
if neg x && neg y
left up buttons pressedelse return to neutral
if pos z
left right buttons pressedelse return to neutral
if neg z
down up buttons pressedelse return to neutral
if pos y && pos x pressed
down right buttons pressedelse return to neutral
if neg y && pos x pressed
up right buttons pressedelse return to neutral
*/
//Touch Sense==============================================
//Standard arrow keys-----------------------------------------
//Touch sensor 1(left)------------------------------------------
//pressure read
touch1 = analogRead(touchPin1);
Serial.print("Touch reading 1 = ");
Serial.print(touch1); // the raw analog reading
//if pressed move left
if (touch1 > 800 && touchReturn1 == 1) {
touchReturn1 = 0;
Keyboard.write(216);
delay(debounce);
Serial.println("Left");
}
//else pressure released
else {
touchReturn1 = 1;
Serial.println("Neutral");
}
//Touch sensor 2(down)------------------------------------------
//pressure read
touch2 = analogRead(touchPin2);
Serial.print("Touch reading 2 = ");
Serial.print(touch2); // the raw analog reading
//if pressed move down
if (touch2 > 800 && touchReturn2 == 1) {
touchReturn2 = 0;
Keyboard.write(217);
delay(debounce);
Serial.println("Down");
}
//else pressure released
else {
touchReturn2 = 1;
Serial.println("Neutral");
}
//Touch sensor 3(up)------------------------------------------
//pressure read
touch3 = analogRead(touchPin3);
Serial.print("Touch reading 3 = ");
Serial.print(touch3); // the raw analog reading
//if pressed move up
if (touch3 > 800 && touchReturn3 == 1) {
touchReturn3 = 0;
Keyboard.write(218);
delay(debounce);
Serial.println("Up");
}
//else pressure released
else {
touchReturn3 = 1;
Serial.println("Neutral");
}
//Touch sensor 4(right)------------------------------------------
//pressure read
touch4 = analogRead(touchPin4);
Serial.print("Touch reading 4 = ");
Serial.print(touch4); // the raw analog reading
//if pressed move left
if (touch4 > 800 && touchReturn4 == 1) {
touchReturn4 = 0;Keyboard.write(215);
delay(debounce);
Serial.println("Right");
}
//else pressure released
else {
touchReturn4 = 1;
Serial.println("Neutral");
}
// 2 Combo arrows--------------------------------------------------
/* if touch 1 && touch 2 pressed
left down buttons pressedelse return to neutral
if touch 1 && touch 3 pressed
left up buttons pressedelse return to neutral
if touch 1 && touch 4 pressed
left right buttons pressedelse return to neutral
if touch 2 && touch 3 pressed
down up buttons pressedelse return to neutral
if touch 2 && touch 4 pressed
down right buttons pressedelse return to neutral
if touch 3 && touch 4 pressed
up right buttons pressedelse return to neutral
*/
//Combo touch and gyro==============================
/* if touch 1 && pos y || touch2 && neg x
left down buttons pressedelse return to neutral
if touch 1 && neg y || touch 3 && neg x
left up buttons pressedelse return to neutral
if touch 1 && pos x || touch 4 && neg x
left right buttons pressedelse return to neutral
if touch 2 && neg y || touch 3 && pos y
down up buttons pressedelse return to neutral
if touch 2 && pos x || touch 4 && pos y
down right buttons pressedelse return to neutral
if touch 3 && pos x || touch 4 && neg y
up right buttons pressedelse return to neutral
*/
//Heart beat neopixels============================
/* pseudo code
for{ //mimic heart beat
setpixel to pink/red pixel color
delay;
clear neopixels
delay;
}
if (A button pressed) {
turn on/off neopixel heart beat}
random thought: It would be great to be able to match the tempo of the song,
but with limited access to the game code,
most likely wont be incorporated
*/
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.