make_controller1


BOM

Item Qty Price/p Link -
Main Board
Seeeduino Xiao 1 5.40 USD Seeed
Pinsocket 1x7 THT 2 0.8 USD Akizuki 1x40 -> 1x7x2P
3.5mm Phone Jack 1 0.50 USD Akizuki Stereo or monaural
2 POS Terminal Block 1 0.20 USD Akizuki 5.08mm pitch
Switch box
Rocker Switch 1 6.00 USD Amazon Momentary on-off-on
Tactical Switch 7 0.40 USD Digikey 12x12mm
Connector
Flat Ribbon Cable 1 0.60 USD Amazon 12m -> 40cm
Pinheader 2x5 THT 1 0.50 USD Akizuki 2x25-> 2x5
Pinheader 2x5 SMD 1 0.80 USD Akizuki 2x20-> 2x5
10 POS Connector 2 0.30 USD Aliexpress
Case
PLA
M3 Bolt 2 Aliexpress 6mm
M3 Nut 2

PCB


download Eagle sch|brd


Program

Library

TinyUSB_Mouse_and_Keyboard

This library provides an Arduino Mouse.h and Keyboard.h compatible API for TinyUSB stack mouse and keyboard control.

#include <TinyUSB_Mouse_and_Keyboard.h>

Arduino Sketch

download ino

  /*
    XIAO USB Keyboard.example.
    http://yuichitamiya.fabcloud.io/fab16/How_to/program/

    Google map help
    https://support.google.com/maps/answer/6396990?co=GENIE.Platform%3DDesktop&hl=ja
    Ctrl+/ to show help menu
  */

  // https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboard
  #include <TinyUSB_Mouse_and_Keyboard.h>

  //HID KEYCODE
  //https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardmodifiers/


  //uint8_t pins[] = { A0 , A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 }; //A9:no-use,A10:JACK_L
  uint8_t pins[] = { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 10}; //9:no-use, 10:JACK_L
  uint8_t pincount = sizeof(pins)/sizeof(pins[0]);


  /*
   Board 2
  |8|4|3|
  |6|<|>|
  |5|0|1|
  |7|x|2|
  */
  uint8_t Key0;
  uint8_t Key1;
  uint8_t Key2;
  uint8_t Key3;
  uint8_t Key4;
  uint8_t Key5;
  uint8_t Key6;
  uint8_t Key7;
  uint8_t Key8;
  uint8_t Key10;


  void setup() {
    Keyboard.begin();
    // led pin
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, HIGH);

    // Set up pin as input
    for (uint8_t i=0; i<pincount; i++)
    {
      pinMode(pins[i], INPUT_PULLUP);// pinMode(0, INPUT_PULLUP); 0 to 8
    }
  }

  void loop() {

    Key0 = digitalRead(pins[0]);
    Key1 = digitalRead(pins[1]);
    Key2 = digitalRead(pins[2]);
    Key3 = digitalRead(pins[3]);
    Key4 = digitalRead(pins[4]);
    Key5 = digitalRead(pins[5]);
    Key6 = digitalRead(pins[6]);
    Key7 = digitalRead(pins[7]);
    Key8 = digitalRead(pins[8]);
    Key10 = digitalRead(pins[9]);//pin10 sensor_in


    // XIAOでは、LOW = On = key pressed
    if (Key0 == LOW ) {
      Key0_act();
    }
    if (Key1 == LOW ) {
      Key1_act();
    }
    if (Key2 == LOW ) {
      Key2_act();
    }
    if (Key3 == LOW ) {
      Key3_act();
    }
    if (Key4 == LOW ) {
      Key4_act();
    }
    if (Key5 == LOW ) {
      Key5_act();
    }
    if (Key6 == LOW ) {
      Key6_act();
    }
    if (Key7 == LOW ) {
      Key7_act();
    }
    if (Key8 == LOW ) {
      Key8_act();
    }
    if (Key10 == LOW ) {//pin10 sensor_in
      Key3_act();
    }
  }


  void Key0_act() {
    // <-
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(400);
    Keyboard.releaseAll();

    digitalWrite(LED_BUILTIN, LOW);// XIAOでは、LOW = On
    KeyRelease();
  }

  void Key1_act() {
    // ->
    Keyboard.press(KEY_LEFT_ARROW);
    delay(400);
    Keyboard.releaseAll();

    digitalWrite(LED_BUILTIN, LOW);
    KeyRelease();
  }

  void Key2_act() {
    // down arrow
    Keyboard.press(KEY_DOWN_ARROW);
    Keyboard.releaseAll();

    digitalWrite(LED_BUILTIN, LOW);
    KeyRelease();
  }

  void Key3_act() {
    // up arrow
    Keyboard.press(KEY_UP_ARROW);
    Keyboard.releaseAll();

    digitalWrite(LED_BUILTIN, LOW);
    KeyRelease();
  }


  void Key4_act() {
    // move to right tab
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press(KEY_RIGHT_ARROW);
    Keyboard.releaseAll();

    digitalWrite(LED_BUILTIN, LOW);
    KeyRelease();
  }

  /*
   Board 2
  |8|4|3|
  |6|<|>|
  |5|0|1|
  |7|x|2|
  */

  void Key8_act() {

   //select url
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.write('l');
    Keyboard.releaseAll();
    delay(100);
    //copy
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.write('c');
    Keyboard.releaseAll();
    delay(1000);

    digitalWrite(LED_BUILTIN, LOW);
    KeyRelease();
  }


  void Key6_act() {

    //move to left tab
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press(KEY_LEFT_ARROW);
    // run spreadsheet script
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press(KEY_LEFT_SHIFT);
    Keyboard.write('1');
    Keyboard.releaseAll();
    delay(3000);
    // paste
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.write('v');
    Keyboard.releaseAll();
    delay(100);

    digitalWrite(LED_BUILTIN, LOW);
    KeyRelease();
  }

  void Key5_act() {

    // move to right tab
    Keyboard.press(KEY_LEFT_GUI);
    Keyboard.press(KEY_RIGHT_ALT);
    Keyboard.press(KEY_RIGHT_ARROW);
    Keyboard.releaseAll();
    // tab to forcus screen
    Keyboard.press(KEY_TAB);

    digitalWrite(LED_BUILTIN, LOW);
    KeyRelease();
  }

  void Key7_act() {
    // tab to forcus screen
    Keyboard.press(KEY_TAB);

    digitalWrite(LED_BUILTIN, LOW);
    KeyRelease();
  }


  void KeyRelease() {
    Keyboard.releaseAll();
    delay(500);
    digitalWrite(LED_BUILTIN, HIGH);// XIAOでは、HIGH = Off
  }

Case


download f3d