Hello everyone!
I have recently decided to build my own GameCube controller for Super Smash Brothers Melee.
I posted a thread about this on a different forum, here is the link if you want to look at it: http://forum.allaboutcircuits.com/threads/using-arcade-buttons-to-replace-an-analog-joystick.128295/
This is a video of the design I am trying to build: https://www.youtube.com/watch?v=UM-NKXS1m2I
Basically, I want to replace a 2 potentiometer joystick with 8 digital arcade buttons (4 cardinal directions, and 4 modifier buttons).
Here is how each potentiometer system would work:
- There are 4 buttons per potentiometer: one triggers full low, one triggers full high, and two are modifiers.
- The modifiers scale the output triggered by the low or high buttons to a configurable percentage from the middle (each modifier has its own percentage).
- The output to the potentiometer goes to the middle value when no buttons are pressed.
- If a either a low or high button is pressed after the other has been held down, the newer button press takes precedence.
I have some questions regarding hardware and software.
In the other thread I posted, I was given two suggestions. One was to output a PWM signal and filter it, and the other was to communicate with a digital potentiometer. I think a digital potentiometer seems like a much better idea. What do you think?
As for the code, I am plotting it out just using USB serial and watching my output there just to get my code right. I figure I can switch it to do whatever output I need later once I have the logic down. I am having some trouble though if anyone can help.
Right now, because of my mediocre knowledge of programming, I am resorting to using a bunch of if statements for the different cases of button combinations I can think of. This seems a bit clunky, is there a better way of doing this? Also, if I do use a digital potentiometer, is there any adverse effect to updating it constantly? Should I only be updating it when I need to or is it not a big deal? If it is a big deal, how can I write a system that only updates it when button changes are detected?
If anyone could give me some advice I would greatly appreciate it! Here is my incomplete code so far for reference:
I have recently decided to build my own GameCube controller for Super Smash Brothers Melee.
I posted a thread about this on a different forum, here is the link if you want to look at it: http://forum.allaboutcircuits.com/threads/using-arcade-buttons-to-replace-an-analog-joystick.128295/
This is a video of the design I am trying to build: https://www.youtube.com/watch?v=UM-NKXS1m2I
Basically, I want to replace a 2 potentiometer joystick with 8 digital arcade buttons (4 cardinal directions, and 4 modifier buttons).
Here is how each potentiometer system would work:
- There are 4 buttons per potentiometer: one triggers full low, one triggers full high, and two are modifiers.
- The modifiers scale the output triggered by the low or high buttons to a configurable percentage from the middle (each modifier has its own percentage).
- The output to the potentiometer goes to the middle value when no buttons are pressed.
- If a either a low or high button is pressed after the other has been held down, the newer button press takes precedence.
I have some questions regarding hardware and software.
In the other thread I posted, I was given two suggestions. One was to output a PWM signal and filter it, and the other was to communicate with a digital potentiometer. I think a digital potentiometer seems like a much better idea. What do you think?
As for the code, I am plotting it out just using USB serial and watching my output there just to get my code right. I figure I can switch it to do whatever output I need later once I have the logic down. I am having some trouble though if anyone can help.
Right now, because of my mediocre knowledge of programming, I am resorting to using a bunch of if statements for the different cases of button combinations I can think of. This seems a bit clunky, is there a better way of doing this? Also, if I do use a digital potentiometer, is there any adverse effect to updating it constantly? Should I only be updating it when I need to or is it not a big deal? If it is a big deal, how can I write a system that only updates it when button changes are detected?
If anyone could give me some advice I would greatly appreciate it! Here is my incomplete code so far for reference:
Code:
void writeToDigitalPot (double inputValue);
int getPotOutput (boolean potLowCurrent,
boolean potLowPrevious,
boolean potHighCurrent,
boolean potHighPrevious);
// Buttons:
const int Left = 0;
const int Right = 1;
const int Down = 2;
const int Up = 3;
const int xMod1 = 4;
const int xMod2 = 5;
const int yMod1 = 6;
const int yMod2 = 7;
boolean LeftPreviousValue = 1;
boolean RightPreviousValue = 1;
void setup()
{
Serial.begin (9600);
pinMode (Left, INPUT_PULLUP);
pinMode (Right, INPUT_PULLUP);
}
void loop()
{
//---------Left Stick X-Axis----------
boolean LeftCurrentValue = digitalRead (Left);
boolean RightCurrentValue = digitalRead (Right);
int xAxisPotValue = getPotOutput (LeftCurrentValue,
LeftPreviousValue,
RightCurrentValue,
RightPreviousValue);
writeToDigitalPot (xAxisPotValue);
LeftPreviousValue = LeftCurrentValue;
RightPreviousValue = RightCurrentValue;
//---------Left Stick Y-Axis----------
}
void writeToDigitalPot (int inputValue)
{
Serial.println (inputValue);
delay (200);
}
int getPotOutput (boolean potLowCurrent,
boolean potLowPrevious,
boolean potHighCurrent,
boolean potHighPrevious)
{
int potOutput = 129;
boolean potLowJustPushed = potLowCurrent == 0
&& potLowPrevious == 1;
boolean potLowJustReleased = potLowCurrent == 1
&& potLowPrevious == 0;
boolean potHighJustPushed = potHighCurrent == 0
&& potHighPrevious == 1;
boolean potHighJustReleased = potHighCurrent == 1
&& potHighPrevious == 0;
if (potLowJustPushed)
{
potOutput = 0;
}
if (potHighJustPushed)
{
potOutput = 257;
}
if (potLowJustPushed && potHighJustPushed)
{
potOutput = 129;
}
if (potHighJustReleased && potLowCurrent == 0)
{
potOutput = 0;
}
if (potLowJustReleased && potHighCurrent == 0)
{
potOutput = 257;
}
if (potHighJustReleased && potLowCurrent == 1)
{
potOutput = 129;
}
if (potLowJustReleased && potHighCurrent == 1)
{
potOutput = 129;
}
if (potLowJustReleased && potHighJustReleased)
{
potOutput = 129;
}
return potOutput;
}