This controller was made to replace the WASD/Arrow keys on the keyboard in an effort to move Pacman around the board. This features 2 forward and backward leaning joysticks that make Pacman steerable and intuitive for movement. I was originally going to fashion something up in terms of a steering wheel and throttle for the forward and back motion however I did not like the idea of reverse and forward changing as the direction of movement varies depending on where you are in the board. I utilized 2 rotary Encoders on here along with the Breadboard and Blue fruit to connect everything together. The hardest part of this entire project has been the coding as it has been since difficult to get the input from 2 rotary encoders to register as different. As seen in the picture we have a rudimentary design for getting the inputs and outputs of the game, The left joystick operates as an up and down motion for Pacman such as the Up and Down Arrow keys, while the right joystick does the Left and Right Arrows in its Up and Down motions. I believe that this was a necessary input change for Pacman as the original designs are very boring to say the least. The simple joystick was created to be just that with no more user feedback needed as it was targeted to be user friendly and easy to understand. This new way to play Pacman will allow players to feel as though they are actually operating him and this will give players more of a stress mechanic they can input into the controllers when you are being chased down by a ghost.
Question: How could I have smoothed out the inputs on the system using these rotary encoders?
#include <Keyboard.h>
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
//Included Variables
int encoder0PinA = A2;
int encoder0PinB = A3;
int encoder0PinC = A1;
int encoder0PinD = A4;
int aState;
int aLastState;
int bState;
int bLastState;
void setup() {
//Setting up Pins
for the inputs
pinMode
(encoder0PinA, INPUT);
pinMode
(encoder0PinB, INPUT);
pinMode
(encoder0PinC, INPUT);
pinMode (encoder0PinD,
INPUT);
Serial.begin (9600);
Keyboard.begin();
//Setting last state
of the pins
aLastState =
digitalRead(encoder0PinD);
bLastState =
digitalRead(encoder0PinB);
}
void loop() {
//Setting starting
state of the pins
aState =
digitalRead(encoder0PinD);
bState =
digitalRead(encoder0PinB);
//Checking if Left
and Right movement state changed
if (aState !=
aLastState){
if
(digitalRead(encoder0PinC) != aState) {
//Moves the
player Right and Depresses all other keys
Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
Keyboard.release(KEY_UP_ARROW);
} else {
//Moves the
player Left and Depresses all other keys
Keyboard.press(KEY_LEFT_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
Keyboard.release(KEY_UP_ARROW);
}
}
//Checking if Up
and Down movement state changed
if (bState !=
bLastState){
if
(digitalRead(encoder0PinA) != bState) {
//Moves the
player Up and Depresses all other keys
Keyboard.press(KEY_UP_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
} else {
//Moves the
player Down and Depresses all other keys
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.release(KEY_UP_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
}
}
aLastState =
aState;
bLastState =
bState;
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.