차이
문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판이전 판다음 판 | 이전 판 | ||
tech:arduino_joystick_for_x-wing_alliance [2016/12/28 21:45] – [배선] V_L | tech:arduino_joystick_for_x-wing_alliance [2021/11/29 13:45] (현재) – 61.74.132.138 | ||
---|---|---|---|
줄 1: | 줄 1: | ||
+ | |||
{{tag> | {{tag> | ||
- | ====== | + | ======아두이노 조이스틱 (Arduino Joystick For X-wing Alliance) ====== |
- | {{INLINETOC}} | + | |
[[/ | [[/ | ||
줄 7: | 줄 7: | ||
그래서 | 그래서 | ||
- | 만들겁니다. | + | 만들것이다. |
+ | |||
+ | * 아날로그 조이스틱 -> USB조이스틱 | ||
+ | * 버튼 6개 추가 (스틱에 2개, 본체에 4개) | ||
+ | * 쓰로틀 추가 | ||
=====준비물===== | =====준비물===== | ||
줄 18: | 줄 22: | ||
https:// | https:// | ||
+ | |||
+ | https:// | ||
+ | https:// | ||
http:// | http:// | ||
줄 26: | 줄 33: | ||
http:// | http:// | ||
- | |||
- | http:// | ||
=====배선===== | =====배선===== | ||
- | * 노랑 그라운드 | + | * 노랑 |
- | * 빨강- 단추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, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | =====미세조정 하는 방법===== | ||
+ | {{: | ||
- | to be continued... | ||