차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판이전 판
다음 판
이전 판
tech:arduino_joystick_for_x-wing_alliance [2016/12/28 10:26] V_Ltech:arduino_joystick_for_x-wing_alliance [2024/07/16 04:29] (현재) – [아두이노 조이스틱 (Arduino Joystick For X-wing Alliance)] V_L
줄 1: 줄 1:
 + 
 {{tag>arduino joystick for x-wing alliance}} {{tag>arduino joystick for x-wing alliance}}
-====== 엑스윙 얼라이언스를 위한 아두이노 조이스틱 (Arduino Joystick For X-wing Alliance) ====== +======아두이노 조이스틱 (Arduino Joystick For X-wing Alliance) ======
-{{INLINETOC}}+
  
 [[/game/x-wing_alliance]]가 스팀으로 발매되었지만 게임패드가 없으면 실행도 안되고 [[tech:joystick|조이스틱]]이 없으면 실질적으로 진행이 불가능하다. [[/game/x-wing_alliance]]가 스팀으로 발매되었지만 게임패드가 없으면 실행도 안되고 [[tech:joystick|조이스틱]]이 없으면 실질적으로 진행이 불가능하다.
줄 7: 줄 7:
 그래서 그래서
  
-만들겁니다.+만들것이다. 
 + 
 +  * 아날로그 조이스틱 -> USB조이스틱 
 +  * 버튼 <del>6개</del> 추가 (스틱에 2개, <del>본체에 4개</del>) -> 키보드가 같이 있어야 하므로 본체 버튼은 별 필요 없는 듯 
 +  * 쓰로틀 추가
  
 =====준비물===== =====준비물=====
줄 18: 줄 22:
  
 https://www.arduino.cc/ https://www.arduino.cc/
 +
 +https://www.arduino.cc/en/Tutorial/Button 
 +https://www.arduino.cc/en/Tutorial/AnalogInput
  
 http://www.instructables.com/id/Arduino-LeonardoMicro-as-Game-ControllerJoystick/?ALLSTEPS http://www.instructables.com/id/Arduino-LeonardoMicro-as-Game-ControllerJoystick/?ALLSTEPS
줄 26: 줄 33:
  
 http://html5gamepad.com/ http://html5gamepad.com/
 +----
 +https://github.com/controllercustom/JoystickWin
 +
 +=====배선=====
 +
 +  * 노랑 - 그라운드
 +  * 빨강 - 단추1
 +  * 주황 - 2
 +  * 보라 - 3
 +  * 회색 - 4
 +
 +====저항연결법====
 +
 +{{https://www.arduino.cc/en/uploads/Tutorial/AnalogReadSerial_sch.png?300}}
 +{{https://www.arduino.cc/en/uploads/Tutorial/PhotoResistorA0_schem.png?300}}
 +
 +====버튼연결법====
 +{{https://www.arduino.cc/en/uploads/Tutorial/button_schem.png?300}}
 +
 +[[http://www.instructables.com/id/Arduino-Button-with-no-resistor/?ALLSTEPS|저항없이 버튼 연결하는 방법]]
 +
 +{{https://cdn.instructables.com/F2N/SZUM/IBL629K9/F2NSZUMIBL629K9.MEDIUM.jpg?300}}
 +
 +초기화를 다르게 해줘야 한다.
 +
 +=====코드=====
 +
 +<file cpp>
 +/*
 +  Wingman Extreme Analog Joystick Modification
 +
 +   Arduino Leonado or micro is needed
 +
 +  // http://www.instructables.com/id/Arduino-Button-with-no-resistor/?ALLSTEPS
 +
 +   Note: on most Arduinos there is already an LED on the board
 +  attached to pin 13.
 +
 +*/
 +
 +#include "Joystick.h"
 +// https://github.com/MHeironimus/ArduinoJoystickLibrary
 +
 +// Create Joystick
 +Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
 +                   JOYSTICK_TYPE_JOYSTICK, 10, 1,
 +                   true, true, false, false, false, false,
 +                   false, true, false, false, false);
 +/*
 +  uint8_t hidReportId,   uint8_t joystickType,  uint8_t buttonCount,  uint8_t hatSwitchCount,
 +  bool includeXAxis,  bool includeYAxis,  bool includeZAxis,  bool includeRxAxis,  bool includeRyAxis,  bool includeRzAxis,
 +  bool includeRudder, bool includeThrottle,  bool includeAccelerator,  bool includeBrake,  bool includeSteering
 +*/
 +
 +// constants won't change. They're used here to
 +// set pin numbers:
 +const int ledPin =  13;      // the number of the LED pin
 +const int hatSwitch = 0;
 +// variables will change:
 +int buttonState = 0;         // variable for reading the pushbutton status
 +
 +int xAxis;
 +int yAxis;
 +int hatRead;
 +
 +void setup() {
 +
 +  // Set Range Values
 +  Joystick.setXAxisRange(-127, 127);
 +  Joystick.setYAxisRange(-127, 127);
 +
 +  Joystick.begin();
 +
 +  // initialize the LED pin as an output:
 +  pinMode(ledPin, OUTPUT);
 +  // initialize the pushbutton pin as an input:
 +  for (int button = 0; button < 10; button++)
 +  {
 +    pinMode(button, INPUT_PULLUP);
 +  }
 +}
 +
 +void loop() {
 +
 +  /*
 +     analog axis
 +  */
 +  xAxis = (analogRead(A0) - 512) / 4;
 +  yAxis = (analogRead(A1) - 512) / 4;
 +  Joystick.setXAxis(xAxis);
 +  Joystick.setYAxis(yAxis);
 +
 +  /*
 +      Throttle
 +  */
 +  Joystick.setThrottle (analogRead(A2)) ;
 +
 +  /*
 +     Hat switch
 +     http://www.epanorama.net/documents/joystick/pc_joystick.html#connector
 +  */
 +  int hatRead = analogRead(A3);
 +
 +  // not pressed : 82kohm 107-108
 +  // 0 : 200ohm 1003
 +  // 90 : 20kohm 333-334
 +  // 180 : 41kohm 195-196
 +  // 270 : 61kohm 140-141
 +
 +  if ((hatRead > 900)  ) {
 +    Joystick.setHatSwitch(hatSwitch, 0);
 +  }
 +  if ((hatRead > 300) && (hatRead < 360)) {
 +    Joystick.setHatSwitch(hatSwitch, 90);
 +  }
 +  if ((hatRead > 180) && (hatRead < 220)) {
 +    Joystick.setHatSwitch(hatSwitch, 180);
 +  }
 +  if ((hatRead > 130) && (hatRead < 160)) {
 +    Joystick.setHatSwitch(hatSwitch, 270);
 +  }
 +  if (hatRead < 120) {
 +    Joystick.setHatSwitch(hatSwitch, -1);
 +  }
 +
 +  /*
 +     Buttons
 +  */
 +
 +  // read the state of pins:
 +  for (int i = 0; i < 10; i++) {
 +
 +    // check if the pushbutton is pressed.
 +    // http://www.instructables.com/id/Arduino-Button-with-no-resistor/?ALLSTEPS
 +    buttonState = digitalRead(i);
 +    if ((buttonState == LOW)  ) {
 +      Joystick.pressButton(i  );
 +      // turn LED on:
 +      digitalWrite(ledPin, HIGH);
 +    } else {
 +      Joystick.releaseButton(i );
 +      // turn LED off:
 +      digitalWrite(ledPin, LOW);
 +    }
 +  }
 +
 +}
 +</file>
 +
 +
 +=====미세조정 하는 방법=====
 +{{:tech:arduino_joystick_for_x-wing_alliance_3509.png}}
 +=====기타=====
 +
 +윈도우 설정에서 못 찾겠으면,
 +
 +> joy.cpl
 +
 +을 실행해 볼 것.
 +
 +
 +{{:tech:arduino_joystick_for_x-wing_alliance_1455.png}}
  
-http://www.instructables.com/id/Arduino-Button-with-no-resistor/?ALLSTEPS+{{:tech:arduino_joystick_for_x-wing_alliance_3754.png}}
  
  
-to be continued...+=====스타워즈 스쿼드론=====
  
 +^버튼^작용^
 +|1|발사|
 +|2| 전방적 선택|
 +|3|좌측 보조무기|
 +|4|우측 보조무기|
 +|5|목표 전환|
 +|6|대응무기 발사|