参考
いろいろ注意
- 過去ログを見てちょん!!!
- 別の所から電源
- 長押しを2回して、androidモード
- 13番のledは、正常接続時に光る
結果
そのまま。
(A)ボタンを押す。
コンパイルの設定
プログラム
//usb_EspUsbHostGamepad_77_ae_esp32_s2_mini_4
//インクルド
#include <Arduino.h> //arduino標準
#include "EspUsbHost.h" //USB関連
//定義
EspUsbHost usb; //USB関連
//num debug
//static void printNum(int c) {
// Serial.print(c);
//} //printNum
//num ln debug
//static void printNumln(int c) {
// Serial.println(c);
//} //printNum
//初期化
void setup() {
//シリアルの初期化 debug
//Serial.begin(115200);
//Serial.print("\n\nSTART\n\n"); //caa45040
//GPIOポートの設定
pinMode(13, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
//ウェート(待ち) なぜか? 必要!!! (双方の準備に時間が掛る?)
digitalWrite(13, HIGH);
delay(3000);
digitalWrite(13, LOW);
delay(500);
//ゲームパッドからのイベントいろいろ (ゲームパッドのボタンが押されたら)
usb.onHIDInput([](const EspUsbHostHIDInput &input) {
// en: Example mapping. Replace VID/PID and usage choices with your controller.
// ja: マッピング例です。VID/PIDとusageの選択はコントローラーに合わせて置き換えてください。
if (input.vid == 0x0079 && input.pid == 0x181c && input.length == 11) { //caa45040
int z;
//a
z = (input.data[6]) & 0x01;
//printNum(z); //debug
digitalWrite(1, z); //GROVEポートのLEDに反映
//b
z = (input.data[6] >> 1) & 0x01;
//printNum(z); //debug
digitalWrite(2, z); //GROVEポートのLEDに反映
//x
z = ((input.data[6]) >> 3) & 0x01;
//printNum(z); //debug
//y
z = ((input.data[6]) >> 4) & 0x01;
//printNum(z); //debug
//printNum(99); //debug
//UE ^
static int p_UE[] = {
1, //0 ^
1, //1
0, //2 ->
0, //3
0, //4 _
0, //5
0, //6 <-
1, //7
0, //8
0, //9
0, //10
0, //11
0, //12
0, //13
0, //14
0 //15 0x0f
};
z = p_UE[(input.data[5]) & 0x0f];
//printNum(z); //debug
//SITA _
static int p_SITA[] = {
0, //0 ^
0, //1
0, //2 ->
1, //3
1, //4 _
1, //5
0, //6 <-
0, //7
0, //8
0, //9
0, //10
0, //11
0, //12
0, //13
0, //14
0 //15 0x0f
};
z = p_SITA[(input.data[5]) & 0x0f];
//printNum(z); //debug
//HIDARI <-
static int p_HIDARI[] = {
0, //0 ^
0, //1
0, //2 ->
0, //3
0, //4 _
1, //5
1, //6 <-
1, //7
0, //8
0, //9
0, //10
0, //11
0, //12
0, //13
0, //14
0 //15 0x0f
};
z = p_HIDARI[(input.data[5]) & 0x0f];
//printNum(z); //debug
//MIGI ->
static int p_MIGI[] = {
0, //0 ^
1, //1
1, //2 ->
1, //3
0, //4 _
0, //5
0, //6 <-
0, //7
0, //8
0, //9
0, //10
0, //11
0, //12
0, //13
0, //14
0 //15 0x0f
};
z = p_MIGI[(input.data[5]) & 0x0f];
//printNum(z); //debug
//printNumln(88); //debug
// en: Raw HID input fires before any keyboard/mouse/vendor-specific parsing.
// ja: Raw HID入力は、キーボード/マウス/ベンダー固有の解析前に通知されます。
//espUsbHostPrint(input);
} //end-if
});
//ゲームパッドの接続イベント
usb.onDeviceConnected([](const EspUsbHostDeviceInfo &device) {
if (device.vid == 0x0079 && device.pid == 0x181c) {
digitalWrite(13, HIGH);
} //end-if
});
//ゲームパッドの切断イベント
usb.onDeviceDisconnected([](const EspUsbHostDeviceInfo &device) {
digitalWrite(13, LOW);
});
//USBの開始
if (!usb.begin()) { //失敗か?
//Lチカさせる
while (1) {
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
} //end-while
} //end-if
delay(1000); //caa45040
} //setup
//メインループ
void loop() {
delay(1); //ダミー //caa45040
} //loop


