Workshop
QT keyboard
ref. How to Make a Fruit Piano on Seeeduino XIAO’s Q-Touch Function
Xiao
ref. Seeeduino XIAO
BOM
Item | Qty |
---|---|
Xiao | 1 |
Jumper wires | 1 - 7 |
Bread Board | (1) |
Setup
ref How to Add Seeed boards to Arduino IDE
Arduino IDE
Additional Boards Manager URLs
File > Preferences
Copy below url to Additional Boards Manager URLs
https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
Board Manager
Tools > Board > Board Manager
Search “xiao”
Install “Seeed SAMD(32 bit ....)Boards”
Board: “Seeduino XIAO”
Port: “/dev/....(Seeduino XIAO)” or COMx (Seeduino XIAO)
Board and Port
Tools > Board
find “Seeeduino XIAO M0”
Library
TinyUSB_Mouse_and_Keyboard
adafruit/Adafruit_FreeTouch
Sketch > Include Library > Add . ZIP Library
Program
Xiao_QT_keyboard.ino
Download -> Double click to open
#include <Adafruit_FreeTouch.h>
Adafruit_FreeTouch qt_0 = Adafruit_FreeTouch(A0, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(A1, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_6 = Adafruit_FreeTouch(A6, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_7 = Adafruit_FreeTouch(A7, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_8 = Adafruit_FreeTouch(A8, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_9 = Adafruit_FreeTouch(A9, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_10 = Adafruit_FreeTouch(A10, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
#include <TinyUSB_Mouse_and_Keyboard.h>
uint8_t Key2;//pin2 bike sensor in
void setup() {
Keyboard.begin();
Serial.begin(115200);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
pinMode(2, INPUT_PULLUP);//pin2 bike sensor in
qt_0.begin();
qt_1.begin();
qt_6.begin();
qt_7.begin();
qt_8.begin();
qt_9.begin();
qt_10.begin();
}
int qt_Threshold = 850;
void loop() {
Key2 = digitalRead(2);//pin2 bike sensor_in
int qt0 = 0;
int qt1 = 0;
int qt6 = 0;
int qt7 = 0;
int qt8 = 0;
int qt9 = 0;
int qt10 = 0;
qt0 = qt_0.measure();
qt1 = qt_1.measure();
qt6 = qt_6.measure();
qt7 = qt_7.measure();
qt8 = qt_8.measure();
qt9 = qt_9.measure();
qt10 = qt_10.measure();
/* Xiao
|USB-C|
|A0_qt0| |5V|
|A1_qt1| |GND|
|A2_bike| |3V3|
|A3| |A10_qt10|
|A4| |A9_qt9|
|A5| |A8_qt8|
|A6_qt6| |A7_qt7|
*/
if (Key2 == LOW ) { //pin2 bike sensor_in // XIAO: LOW means On = key pressed
Key3_act();
}
if (qt0 >= qt_Threshold) {
Serial.print("qt0: "); Serial.println(qt0);
Key2_act();
}
if (qt1 >= qt_Threshold) {
Serial.print("qt1: "); Serial.println(qt1);
Key1_act();
}
if (qt6 >= qt_Threshold) {
Serial.print("qt6: "); Serial.println(qt6);
Key3_act();
}
if (qt7 >= qt_Threshold) {
Serial.print("qt7: "); Serial.println(qt7);
Key0_act();
}
if (qt8 >= qt_Threshold) {
Serial.print("qt8: "); Serial.println(qt8);
Key1_act();
}
if (qt9 >= qt_Threshold) {
Serial.print("qt9: "); Serial.println(qt9);
Key4_act();
}
if (qt10 >= qt_Threshold) {
Serial.print("qt10: "); Serial.println(qt10);
Key3_act();
}
//delay(100);
}
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);
delay(400);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key3_act() {
// up arrow
Keyboard.press(KEY_UP_ARROW);
delay(200);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void Key4_act() {
// feedback
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.write('f');
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
KeyRelease();
}
void KeyRelease() {
Keyboard.releaseAll();
delay(500);
digitalWrite(LED_BUILTIN, HIGH);// XIAO HIGH = Off
}
Keyboard Functions & Parameters
ref .TinyUSB_Mouse_and_Keyboard/examples/TinyUSB_Keyboard_Test/TinyUSB_Keyboard_Test.ino
Keyboard Functions
/*Example Keyboard.write('a'); //press and release 'a' key uint8_t Multiple[3]= {'1','2','3'}; Keyboard.write(Multiple,3); //multiple keys sequentially from a buffer Keyboard.print("456"); //print a string Keyboard.println("789"); //print another string with a line Keyboard.press(KEY_LEFT_SHIFT); //hold down the shift Keyboard.println("a uppercase sentence"); //this will be all caps Keyboard.release(KEY_LEFT_SHIFT);//release the shift Keyboard.println ("back to lowercase"); Keyboard.press(KEY_LEFT_SHIFT); //press shift Keyboard.println("1234"); //some text Keyboard.releaseAll(); //release all Keyboard.println("1234"); //not shifted Keyboard.print("A mistake"); //will attempt to erase this delay(1000); Keyboard.press(KEY_LEFT_CTRL); //will attempt control-z Keyboard.write('z'); Keyboard.releaseAll(); //release the control key */
Key code
ref. TinyUSB_Mouse_and_Keyboard/TinyUSB_Mouse_and_Keyboard.h
Key code
/****************************** * KEYBOARD SECTION ******************************/ // Keyboard codes // Note these are different in some respects to the TinyUSB codes but // are compatible with Arduino Keyboard.h API #define KEY_LEFT_CTRL 0x80 #define KEY_LEFT_SHIFT 0x81 #define KEY_LEFT_ALT 0x82 #define KEY_LEFT_GUI 0x83 #define KEY_RIGHT_CTRL 0x84 #define KEY_RIGHT_SHIFT 0x85 #define KEY_RIGHT_ALT 0x86 #define KEY_RIGHT_GUI 0x87 #define KEY_UP_ARROW 0xDA #define KEY_DOWN_ARROW 0xD9 #define KEY_LEFT_ARROW 0xD8 #define KEY_RIGHT_ARROW 0xD7 #define KEY_BACKSPACE 0xB2 #define KEY_TAB 0xB3 #define KEY_RETURN 0xB0 #define KEY_ESC 0xB1 #define KEY_INSERT 0xD1 #define KEY_DELETE 0xD4 #define KEY_PAGE_UP 0xD3 #define KEY_PAGE_DOWN 0xD6 #define KEY_HOME 0xD2 #define KEY_END 0xD5 #define KEY_CAPS_LOCK 0xC1 #define KEY_F1 0xC2 #define KEY_F2 0xC3 #define KEY_F3 0xC4 #define KEY_F4 0xC5 #define KEY_F5 0xC6 #define KEY_F6 0xC7 #define KEY_F7 0xC8 #define KEY_F8 0xC9 #define KEY_F9 0xCA #define KEY_F10 0xCB #define KEY_F11 0xCC #define KEY_F12 0xCD #define KEY_F13 0xF0 #define KEY_F14 0xF1 #define KEY_F15 0xF2 #define KEY_F16 0xF3 #define KEY_F17 0xF4 #define KEY_F18 0xF5 #define KEY_F19 0xF6 #define KEY_F20 0xF7 #define KEY_F21 0xF8 #define KEY_F22 0xF9 #define KEY_F23 0xFA #define KEY_F24 0xFB
OS
ref Keyboard.press()
Windows and Linux
- Windows key: KEY_LEFT_GUI
- Control key: KEY_LEFT_CTRL
mac
- command key: KEY_LEFT_GUI
- control key: KEY_LEFT_CTRL
// use this option for OSX:
char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux:
// char ctrlKey = KEY_LEFT_CTRL;
Keyboard.press(ctrlKey);