Commit 6257aff3 authored by yuichitamiya's avatar yuichitamiya
Browse files

add How to /make_controller1

parent eadc5240
Pipeline #242816 passed with stage
in 36 seconds
# make_controller1
![](../images/make/board2.jpg){width=800}
---
## BOM
|Item |Qty |Price/p|Link|-|
|-- |:--:|-- |--|--|
|*Main Board*| | | | |
|Seeeduino Xiao| 1|5.40 USD |[Seeed](https://www.seeedstudio.com/Seeeduino-XIAO-Arduino-Microcontroller-SAMD21-Cortex-M0+-p-4426.html)|
|Pinsocket 1x7 THT| 2| 0.8 USD|[Akizuki](https://akizukidenshi.com/catalog/g/gC-10073/)|1x40 -> 1x7x2P
|3.5mm Phone Jack| 1|0.50 USD |[Akizuki](https://akizukidenshi.com/catalog/g/gC-02460/)| Stereo or monaural
|2 POS Terminal Block| 1|0.20 USD |[Akizuki](https://akizukidenshi.com/catalog/g/gP-02333/)|5.08mm pitch
|*Switch box* | | | | |
|Rocker Switch | 1|6.00 USD |[Amazon](https://www.amazon.co.jp/gp/product/B0768G4LZ8)| Momentary on-off-on
|Tactical Switch| 7|0.40 USD|[Digikey](https://www.digikey.jp/product-detail/en/c-k/PTS125SM43-2-LFS/CKN9100-ND/1146743?cur=USD&lang=en)|12x12mm
|*Connector* | | | | |
|Flat Ribbon Cable| 1|0.60 USD|[Amazon](https://www.amazon.co.jp/gp/product/B01DZA0OKW/ref=ppx_yo_dt_b_d_asin_title_o00?ie=UTF8&psc=1)|12m -> 40cm
|Pinheader 2x5 THT| 1|0.50 USD|[Akizuki](https://akizukidenshi.com/catalog/g/gC-00081/)|2x25-> 2x5
|Pinheader 2x5 SMD| 1|0.80 USD|[Akizuki](https://akizukidenshi.com/catalog/g/gC-06098/)|2x20-> 2x5
|10 POS Connector | 2|0.30 USD|[Aliexpress](https://ja.aliexpress.com/item/4000114961257.html) |
|*Case* | | | | |
|PLA | | | |
|M3 Bolt| 2| | [Aliexpress](https://ja.aliexpress.com/item/33022099174.html?spm=a2g0s.9042311.0.0.27424c4d8DGf45) |6mm
|M3 Nut| 2| | | |
---
## PCB
![](../images/make/board2_main.jpg){width=300}
![](../images/make/board2_sw.jpg){width=410}
![](../eagle/b2/b2sch.png){width=800}
![](../eagle/b2/b2brd.png){width=800}
download Eagle [sch](../eagle/b2/b2.brd)|[brd](../eagle/b2/b2.sch)
---
## Program
### Library
[TinyUSB_Mouse_and_Keyboard](https://github.com/cyborg5/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](../sketch/map2_for_b2/map2_for_b2.ino)
<details closed>
<summary>map2_for_b2.ino</summary>
<pre>
/*
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>
//#include &lt;TinyUSB_Mouse_and_Keyboard.h&gt;
//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
}
</pre>
</details>
---
## Case
![](../images/make/case_1.png){width=400}
![](../images/make/case_2.png){width=400}
[download f3d](../files/controller1.f3d)
#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);
Key0_act();
}
if (qt1 >= qt_Threshold) {
Serial.print("qt1: "); Serial.println(qt1);
Key1_act();
}
if (qt6 >= qt_Threshold) {
Serial.print("qt6: "); Serial.println(qt6);
Key2_act();
}
if (qt7 >= qt_Threshold) {
Serial.print("qt7: "); Serial.println(qt7);
Key3_act();
}
if (qt8 >= qt_Threshold) {
Serial.print("qt8: "); Serial.println(qt8);
Key3_act();
}
if (qt9 >= qt_Threshold) {
Serial.print("qt9: "); Serial.println(qt9);
Key3_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);
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 KeyRelease() {
Keyboard.releaseAll();
delay(500);
digitalWrite(LED_BUILTIN, HIGH);// XIAOでは、HIGH = Off
}
/*********************************************************************
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
......
......@@ -5,31 +5,37 @@
Google map help
https://support.google.com/maps/answer/6396990?co=GENIE.Platform%3DDesktop&hl=ja
Ctrl+/ to show help menu
a or ← :left
d or →:right
*/
// https://github.com/cyborg5/TinyUSB_Mouse_and_Keyboard
#include <TinyUSB_Mouse_and_Keyboard.h>
//#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]);
uint8_t pins[] = { A0 , A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 }; //A9: nouse,A10:JACK_L
uint8_t Key0; //A0
uint8_t Key1; //A1
uint8_t Key2; //A2
uint8_t Key3; //A3
uint8_t Key4; //A4
uint8_t Key5; //A5
uint8_t Key6; //A6
uint8_t Key7; //A7
uint8_t Key8; //A8
//uint8_t Key9; //A9 nouse
/*
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() {
......@@ -37,19 +43,16 @@ void setup() {
// 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);
pinMode(pins[4], INPUT_PULLUP);
pinMode(pins[5], INPUT_PULLUP);
pinMode(pins[6], INPUT_PULLUP);
pinMode(pins[7], INPUT_PULLUP);
pinMode(pins[8], INPUT_PULLUP);
// 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]);
......@@ -59,9 +62,11 @@ void loop() {
Key6 = digitalRead(pins[6]);
Key7 = digitalRead(pins[7]);
Key8 = digitalRead(pins[8]);
Key10 = digitalRead(pins[9]);//pin10 sensor_in
// XIAOでは、LOW = On
if (Key0 == LOW ) { //
// XIAOでは、LOW = On = key pressed
if (Key0 == LOW ) {
Key0_act();
}
if (Key1 == LOW ) {
......@@ -88,17 +93,16 @@ void loop() {
if (Key8 == LOW ) {
Key8_act();
}
if (Key10 == LOW ) {//pin10 sensor_in
Key3_act();
}
}
void Key0_act() {
// <-
//Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.press('d');
//Keyboard.write('D');
//delay(100);
Keyboard.press(KEY_RIGHT_ARROW);
delay(400);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);// XIAOでは、LOW = On
......@@ -107,11 +111,8 @@ void Key0_act() {
void Key1_act() {
// ->
//Keyboard.press(KEY_LEFT_ARROW);
Keyboard.press('a');
//Keyboard.write('A');
//delay(100);
Keyboard.press(KEY_LEFT_ARROW);
delay(400);
Keyboard.releaseAll();
digitalWrite(LED_BUILTIN, LOW);
......@@ -136,6 +137,7 @@ void Key3_act() {
KeyRelease();
}
void Key4_act() {
// move to right tab
Keyboard.press(KEY_LEFT_GUI);
......@@ -147,8 +149,17 @@ void Key4_act() {
KeyRelease();
}
void Key6_act() {
//select url
/*
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();
......@@ -157,18 +168,19 @@ void Key6_act() {
Keyboard.press(KEY_LEFT_GUI);
Keyboard.write('c');
Keyboard.releaseAll();
delay(100);
//move to left tab
Keyboard.press(KEY_LEFT_GUI);
Keyboard.press(KEY_RIGHT_ALT);
Keyboard.press(KEY_LEFT_ARROW);
Keyboard.releaseAll();
delay(1000);