- 【neGcon】ネジコンを使い続ける者達のスレ2
15 :sage[]:2020/07/02(木) 23:51:42.68 ID:JEet1b+3 - 幾つかのHPを参考に、Arduino LeonardoでPCにxboxコントローラとして認識できた。
(UNOとかMEGAではだめで、Leonardoが必要) 接続: NeGcon 1, 2, 3, 4, 5, 6, 7, 8 Leonardo MISO, MOSI, -, GND, 5V, D3, SCK, - MISOと5Vの間に1kΩ ライブラリ: ttps://github.com/dmadison/ArduinoXInput
| - 【neGcon】ネジコンを使い続ける者達のスレ2
16 :sage[]:2020/07/02(木) 23:53:09.44 ID:JEet1b+3 - コード:
#include <SPI.h> #include <XInput.h> #define TRANSFER_WAIT 16 #define FRAME_WAIT 16 const byte CMD[] = {0x01, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; const byte CMD_BYTES = sizeof CMD; byte DAT[CMD_BYTES] = {0}; void setup() { SPI.setBitOrder(LSBFIRST); SPI.setClockDivider(SPI_CLOCK_DIV64); SPI.setDataMode(SPI_MODE3); SPI.begin(); pinMode(MISO, INPUT); pinMode(3, HIGH); XInput.setRange(JOY_LEFT, 0, 255); XInput.setRange(TRIGGER_RIGHT, 5, 200); XInput.setRange(TRIGGER_LEFT, 5, 200); XInput.begin(); }
| - 【neGcon】ネジコンを使い続ける者達のスレ2
17 :sage[]:2020/07/02(木) 23:53:25.10 ID:JEet1b+3 - void loop() {
digitalWrite(3, LOW); delayMicroseconds(TRANSFER_WAIT); for (byte i = 0; i < CMD_BYTES; i++) { DAT[i] = SPI.transfer(CMD[i]); delayMicroseconds(TRANSFER_WAIT); } digitalWrite(3, HIGH); delay(FRAME_WAIT); XInput.setButton(DPAD_LEFT, !((DAT[3] >> 7) & 1)); XInput.setButton(DPAD_DOWN, !((DAT[3] >> 6) & 1)); XInput.setButton(DPAD_RIGHT, !((DAT[3] >> 5) & 1)); XInput.setButton(DPAD_UP, !((DAT[3] >> 4) & 1)); XInput.setButton(BUTTON_START, !((DAT[3] >> 3) & 1)); XInput.setButton(BUTTON_B, !((DAT[4] >> 5) & 1)); XInput.setButton(BUTTON_A, !((DAT[4] >> 4) & 1)); XInput.setButton(BUTTON_RB, !((DAT[4] >> 3) & 1)); XInput.setJoystick(JOY_LEFT, DAT[5], 128); XInput.setTrigger(TRIGGER_LEFT, DAT[8]); /// Lブレーキ XInput.setTrigger(TRIGGER_RIGHT, DAT[7]); // XInput.setButton(BUTTON_LB, DAT[8] > 128); XInput.send(); }
| - 【neGcon】ネジコンを使い続ける者達のスレ2
18 :sage[sage]:2020/07/02(木) 23:55:32.79 ID:JEet1b+3 - sage失敗?
不慣れですまん。
|
|