program

map3cp_for _b2

(program ver.3 circuit python for Google_map for board ver.2)

ref. Build a simple USB HID Macropad using Seeeduino Xiao & CircuitPython

ref. SeeeduinoXIAOでCircuitPythonをインストールして動作させる

ref. Creating and Editing Code

    Naming Your Program File
    CircuitPython looks for a code file on the board to run.  
    There are four options:
    - code.txt  
    - code.py  
    - main.txt
    - main.py     
    CircuitPython looks for those files, in that order, and then runs the first one it finds.   
    While we suggest using code.py as your code file

ref. Adafruit HID Library


map2_for_b2

(program ver.2 for Google_map for board ver.2)

ref. XIAOでMacのスクリーンショット専用USBキーを作るDIY

Library

TinyUSB_Mouse_and_Keyboard

ref. Sample: xiao_usb1.ino

xiao_usb1.ino
/*
 * Sample program demonstrating TinyUSB_Mouse_and_Keyboard.h module which
 * auto selects between standard Arduino Mouse.h API and TinyUSB mouse API.
 * This program tests the keyboard portion alone.
 */

//Include this module whether using Arduino stack or TinyUSB stack
// https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboards
#include 

// Launchpad sc > F5
void setup() {
  Keyboard.begin();   //Unlike Arduino Keyboard.h, you must use begin.
  Serial.begin(115200);
  while (! Serial)delay (1);
  //Serial.println("USB keyboard test");

  //find terminal
  Keyboard.write(KEY_F5);
  Keyboard.press(KEY_LEFT_GUI);//command

  delay(100);
  Keyboard.write('f');
  Keyboard.releaseAll();
  delay(100);
  // 英字モードに変更。CTL+SHIFT+;
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press(KEY_LEFT_SHIFT);
  Keyboard.write(';');
  Keyboard.releaseAll();
  delay(100);
  Keyboard.print("terminal");
  delay(500);
  Keyboard.press(KEY_RETURN);
  Keyboard.releaseAll();
  delay(200);
  // New terminal windows
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.write('n');
  Keyboard.releaseAll();
  //open site
  Keyboard.print("open http://yuichitamiya.fabcloud.io/fab16/");
  Keyboard.press(KEY_RETURN);

  Keyboard.releaseAll();         //release the control key
  Serial.println("USB keyboard test completed");
};
void loop() {
}

/*
 * Click below before uploading and it will type characters in this comment
 *
 *
 *  
 *  
 *  
 *  
 *  
 *  
 */


ref. 4 button keyboard: ss-key.ino

ss-key.ino
/*
  XIAO USB Keyboard.example.
  https://junkhack.gpl.jp/2021/03/01/make-mac-sskey-xiao/
*/

// https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboard
//#include 
#include "TinyUSB_Mouse_and_Keyboard.h"

uint8_t pins[] = { A7 , A8 , A9 , A10 };
uint8_t Key0; //A7
uint8_t Key1; //A8
uint8_t Key2; //A9
uint8_t Key3; //A10
// 残り7Pin

void setup() {
  Keyboard.begin();
  // led pin
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  //
  pinMode(pins[0], INPUT_PULLUP);
  pinMode(pins[1], INPUT_PULLUP);
  pinMode(pins[2], INPUT_PULLUP);
  pinMode(pins[3], INPUT_PULLUP);
}

void loop() {
  Key0 = digitalRead(pins[0]);
  Key1 = digitalRead(pins[1]);
  Key2 = digitalRead(pins[2]);
  Key3 = digitalRead(pins[3]);

  if (Key0 == LOW ) {       // XIAOでは、LOW = On
      Key0_act();
  }
  if (Key1 == LOW ) {
      skitch_ss();
  }
  if (Key2 == LOW ) {
      skitch_pict_copy();
  }
  if (Key3 == LOW ) {
      Key3_act();
  }
}

void Key0_act() {
  // esc
  Keyboard.write(KEY_ESC);

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

void skitch_pict_copy() {
  //find skitch
  Keyboard.write(KEY_F5);
  Keyboard.press(KEY_LEFT_GUI);
  delay(100);
  Keyboard.write('f');
  Keyboard.releaseAll();
  delay(100);
  // 英字モードに変更する必要ある。CTL+SHIFT+;
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press(KEY_LEFT_SHIFT);
  Keyboard.write(';');
  Keyboard.releaseAll();
  delay(100);
  Keyboard.print("skitch");
  delay(500);
  Keyboard.press(KEY_RETURN);
  Keyboard.releaseAll();
  delay(200);
  // skitch pict copy
  Keyboard.press(KEY_LEFT_SHIFT);
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.write('c');
  Keyboard.releaseAll();
  delay(100);
  // ひらがなモードに変更。CTL+SHIFT+j
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press(KEY_LEFT_SHIFT);
  Keyboard.write('j');
  Keyboard.releaseAll();

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

void skitch_ss() {
  // skitch
  Keyboard.press(KEY_LEFT_SHIFT);
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.write('5');

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

void Key3_act() {
  //find terminal
  Keyboard.write(KEY_F5);
  Keyboard.press(KEY_LEFT_GUI);
  delay(100);
  Keyboard.write('f');
  Keyboard.releaseAll();
  delay(100);
  // 英字モードに変更する必要ある。CTL+SHIFT+;
  Keyboard.press(KEY_LEFT_CTRL);
  Keyboard.press(KEY_LEFT_SHIFT);
  Keyboard.write(';');
  Keyboard.releaseAll();
  delay(100);
  Keyboard.print("terminal");
  delay(500);
  Keyboard.press(KEY_RETURN);
  Keyboard.releaseAll();
  delay(200);
  // New terminal windows
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.write('n');
  Keyboard.releaseAll();
  //open URL
  Keyboard.print("open https://www.canva.com/");
  Keyboard.press(KEY_RETURN);

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

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