찾기
내용으로 건너뛰기
추적
문서의 이전 판을 선택했습니다!
저장하면 이 자료로 새 판을 만듭니다.
미디어 파일
{{tag>arduino joystick for x-wing alliance}} ====== 엑스윙 얼라이언스를 위한 아두이노 조이스틱 (Arduino Joystick For X-wing Alliance) ====== [[/game/x-wing_alliance]]가 스팀으로 발매되었지만 게임패드가 없으면 실행도 안되고 [[tech:joystick|조이스틱]]이 없으면 실질적으로 진행이 불가능하다. 그래서 만들것이다. * 아날로그 조이스틱 -> USB조이스틱 * 버튼 6개 추가 (스틱에 2개, 본체에 4개) * 쓰로틀 추가 =====준비물===== *[[arduino|아두이노 레오나르도]] [[http://search.danawa.com/dsearch.php?query=Arduino+Leonardo+R3&tab=main&volumeType=|(다나와 8900원)]] {{:tech:arduino_joystick_for_x-wing_alliance_1228113001.png?300}} {{:tech:arduino_joystick_for_x-wing_alliance_1228105911.png}} 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 https://github.com/MHeironimus/ArduinoJoystickLibrary [[https://github.com/MHeironimus/ArduinoJoystickLibrary/tree/version-1.0|1.0]] https://github.com/MHeironimus/ClassicJoystickAdaptor http://html5gamepad.com/ =====배선===== * 노랑 - 그라운드 * 빨강 - 단추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> =====미세조정 하는 방법=====
2+1?
이 필드는 비어 있도록 유지하세요:
저장
미리 보기
취소
편집 요약
참고: 이 문서를 편집하면 내용은 다음 라이선스에 따라 배포하는 데 동의하는 것으로 간주합니다:
CC Attribution-Noncommercial-Share Alike 4.0 International
문서 도구
문서 보기
이전 판
연결문서
맨 위로
다크 모드로 보기
☀️
Toggle Menu
기술
너두 고쳐두 됩니다.
사이트 도구
최근 바뀜
미디어 관리자
사이트맵
사용자 도구
등록
로긴
최근 수정된 문서
misuse_topical5
노박
unique_items
dinner_bell
deputy_beagle
ratslayer
one_for_my_baby
alerio
power_fist
제거됨
fixer
climb_ev_ry_mountain
companion
[장비 분실]
crashed_vertibird
brotherhood_t-51b_power_armor
marco
i_forgot_to_remember_to_forget
cateye