kiteretro / Circuit-Sword-Lite

GNU General Public License v3.0
24 stars 1 forks source link

CSL Joystick Configure? #8

Closed nesjess closed 5 years ago

nesjess commented 5 years ago

Hi! Sorry if this was addressed, but I can't find any info on how to configure the joystick on the CSL. I only see instructions in the CS FAQs, but that doesn't work for the CSL. Thanks!

kiteretro commented 5 years ago

Hi, how have you wired it up? The CSL does not support an analog stick, the extra pads I think you have found are labelled "digital joystick" and these are digital inputs. Pulling any of these pins LOW will trigger a button to be pressed (no calibration needed)

nesjess commented 5 years ago

Got it. I didn’t notice it was digital even though it says it right there on the CSL. Haha.

Is there a way to convert to analog? Thanks for the quick response!

kiteretro commented 5 years ago

There is :) do you like projects? .. what you need to do is get something like an Arduino Leonardo and write a short program to read the analog value, and convert it to a digital press. The pads on the CSL work by all being defaulted at 3.3v (HIGH) .. if you bring the pad to GND (LOW) it will register as a button :) so, the program you need to write will go something like:

#define PIN_LEFT 10
#define PIN_RIGHT 11
#define PIN_UP 12
#define PIN_DOWN 13

#define PIN_JOY_X A0
#define PIN_JOY_Y A1

void setup() {

}

void loop() {
  int joy_x = analogRead(PIN_JOY_X);
  int joy_y = analogRead(PIN_JOY_Y);

  if (joy_x < 200) {
    pinMode(PIN_LEFT, OUTPUT);
    pinMode(PIN_RIGHT, INPUT);
  } else if (joy_x > 800) {
    pinMode(PIN_LEFT, INPUT);
    pinMode(PIN_RIGHT, OUTPUT);
  } else {
    pinMode(PIN_LEFT, INPUT);
    pinMode(PIN_RIGHT, INPUT);
  }

  if (joy_y < 200) {
    pinMode(PIN_DOWN, OUTPUT);
    pinMode(PIN_UP, INPUT);
  } else if (joy_y > 800) {
    pinMode(PIN_DOWN, INPUT);
    pinMode(PIN_UP, OUTPUT);
  } else {
    pinMode(PIN_DOWN, INPUT);
    pinMode(PIN_UP, INPUT);
  }
}

This works safely by "not pressing" the buttons with pinMode INPUT, and then "pressing the button low" by enabling the pin with pinMode OUTPUT.

You can then power the Arduino from the 3.3v pad that is right next to it. Fair warning though, don't connect to the 3.3v at the same time as plugging in the USB to the Ardunio! Unless of course you use the 3.3v rated Arduino (running a 5v arduino on 3.3v is fine)

nesjess commented 5 years ago

Seems pretty easy. ;)

Not sure how that would all fit in the DMG case, but thanks for the info. I should have checked for this before drilling a hole in my case. Lol.

Thanks again for the wonderful product.