차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| tech:arduino_joystick_for_x-wing_alliance [2016/12/31 08:32] – V_L | tech:arduino_joystick_for_x-wing_alliance [2024/07/16 04:29] (현재) – [아두이노 조이스틱 (Arduino Joystick For X-wing Alliance)] V_L | ||
|---|---|---|---|
| 줄 1: | 줄 1: | ||
| + | |||
| {{tag> | {{tag> | ||
| - | ======  | + | ======아두이노 조이스틱 (Arduino Joystick For X-wing Alliance) ====== | 
| - | {{INLINETOC}} | + | |
| [[/ | [[/ | ||
| 줄 7: | 줄 7: | ||
| 그래서 | 그래서 | ||
| - | 만들겁니다. | + | 만들것이다. | 
| + | |||
| + | * 아날로그 조이스틱 -> USB조이스틱 | ||
| + |   * 버튼 < | ||
| + | * 쓰로틀 추가 | ||
| =====준비물===== | =====준비물===== | ||
| 줄 18: | 줄 22: | ||
| https:// | https:// | ||
| - | |||
| https:// | https:// | ||
| 줄 30: | 줄 33: | ||
| http:// | http:// | ||
| - | + | ---- | |
| - | http://www.instructables.com/id/ | + | https://github.com/controllercustom/JoystickWin | 
| =====배선===== | =====배선===== | ||
| - | * 노랑 그라운드 | + |   * 노랑  | 
| - | * 빨강- 단추1 | + | * 빨강 - 단추1 | 
| - | * 주황- 2 | + | * 주황 - 2 | 
| - | * 보라- 3 | + | * 보라 - 3 | 
| - | * 회색- 4 | + | * 회색 - 4 | 
| + | |||
| + | ====저항연결법==== | ||
| + | |||
| + | {{https:// | ||
| + | {{https:// | ||
| + | |||
| + | ====버튼연결법==== | ||
| + | {{https:// | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | {{https:// | ||
| + | |||
| + | 초기화를 다르게 해줘야 한다. | ||
| + | |||
| + | =====코드===== | ||
| + | |||
| + | <file cpp> | ||
| + | /* | ||
| + | Wingman Extreme Analog Joystick Modification | ||
| + | |||
| + |     | ||
| + | |||
| + |   // http:// | ||
| + | |||
| + | Note: on most Arduinos there is already an LED on the board | ||
| + | attached to pin 13. | ||
| + | |||
| + | */ | ||
| + | |||
| + | #include " | ||
| + | // https:// | ||
| + | |||
| + | // Create Joystick | ||
| + | Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, | ||
| + |                     | ||
| + | true, true, false, false, false, false, | ||
| + |                     | ||
| + | /* | ||
| + |   uint8_t hidReportId,  | ||
| + |   bool includeXAxis,  | ||
| + |   bool includeRudder, | ||
| + | */ | ||
| + | |||
| + | // constants won't change. They' | ||
| + | // 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, | ||
| + |   Joystick.setYAxisRange(-127, | ||
| + | |||
| + |   Joystick.begin(); | ||
| + | |||
| + | // initialize the LED pin as an output: | ||
| + |   pinMode(ledPin, | ||
| + | // initialize the pushbutton pin as an input: | ||
| + | for (int button = 0; button < 10; button++) | ||
| + | { | ||
| + |     pinMode(button, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | |||
| + | /* | ||
| + |       | ||
| + | */ | ||
| + | xAxis = (analogRead(A0) - 512) / 4; | ||
| + | yAxis = (analogRead(A1) - 512) / 4; | ||
| + |   Joystick.setXAxis(xAxis); | ||
| + |   Joystick.setYAxis(yAxis); | ||
| + | |||
| + | /* | ||
| + | Throttle | ||
| + | */ | ||
| + | Joystick.setThrottle (analogRead(A2)) ; | ||
| + | |||
| + | /* | ||
| + | Hat switch | ||
| + |       | ||
| + | */ | ||
| + |   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, | ||
| + | } | ||
| + | if ((hatRead > 300) && (hatRead < 360)) { | ||
| + |     Joystick.setHatSwitch(hatSwitch, | ||
| + | } | ||
| + | if ((hatRead > 180) && (hatRead < 220)) { | ||
| + |     Joystick.setHatSwitch(hatSwitch, | ||
| + | } | ||
| + | if ((hatRead > 130) && (hatRead < 160)) { | ||
| + |     Joystick.setHatSwitch(hatSwitch, | ||
| + | } | ||
| + | if (hatRead < 120) { | ||
| + |     Joystick.setHatSwitch(hatSwitch, | ||
| + | } | ||
| + | |||
| + | /* | ||
| + |       | ||
| + | */ | ||
| + | |||
| + | // read the state of pins: | ||
| + | for (int i = 0; i < 10; i++) { | ||
| + | |||
| + | // check if the pushbutton is pressed. | ||
| + |     // http:// | ||
| + |     buttonState = digitalRead(i); | ||
| + | if ((buttonState == LOW) ) { | ||
| + |       Joystick.pressButton(i  | ||
| + | // turn LED on: | ||
| + |       digitalWrite(ledPin, | ||
| + | } else { | ||
| + | Joystick.releaseButton(i ); | ||
| + | // turn LED off: | ||
| + |       digitalWrite(ledPin, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | =====미세조정 하는 방법===== | ||
| + | {{: | ||
| + | =====기타===== | ||
| + | |||
| + | 윈도우 설정에서 못 찾겠으면, | ||
| + | |||
| + | > joy.cpl | ||
| + | |||
| + | 을 실행해 볼 것. | ||
| + | |||
| + | |||
| + | {{: | ||
| + | |||
| + | {{: | ||
| - | to be continued... | + | =====스타워즈 스쿼드론===== | 
| + | ^버튼^작용^ | ||
| + | |1|발사| | ||
| + | |2| 전방적 선택| | ||
| + | |3|좌측 보조무기| | ||
| + | |4|우측 보조무기| | ||
| + | |5|목표 전환| | ||
| + | |6|대응무기 발사| | ||