-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
744 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* 解説: https://zenn.dev/ukkz/articles/02c243a6ba7795 | ||
* | ||
* <注意> | ||
* あらかじめ "Sutra Writer" でEEPROMに使用したいお経を書き込んでおくこと | ||
* | ||
* <記事解説からの変更点> | ||
* ・PROGMEMでも厳しくなったのでEEPROMに格納したバイト列から変換するようにしました。 | ||
* ・Stringはメモリ消費が激しいので通常のchar列で文字列表現しています。 | ||
*/ | ||
|
||
#include <EEPROM.h> | ||
|
||
class Chanting { | ||
private: | ||
int cursor = 0; // 読経位置インデックス | ||
bool finished = false; // 末端まで達したか | ||
char output[12] = ""; // 最大5文字 + 改行コード等最大3文字 + スペース予備3文字 + 終端 = 12 | ||
char enterCode[4]; // CR,LF,CR+LF,space+CRLFなど(WinやMacなど環境にあわせてコンストラクタで設定のこと) | ||
// 以下 文字数ごとの音節配列 | ||
char syl_1[4][2] = { "a", "i", "u", "e" }; | ||
char syl_2[26][3] = { "ka", "ku", "ke", "ko", "si", "ta", "ti", "ni", "ne", "ha", "fu", "ma", "mi", "mu", "ge", "go", "ze", "ji", "ju", "jo", "do", "bi", "bu", "bo", "ra", "ri" }; | ||
char syl_3[24][4] = { "kai", "kuu", "kou", "sai", "sou", "tei", "tou", "nai", "nou", "hou", "gya", "sha", "shu", "sho", "zai", "zou", "jou", "dai", "dou", "nya", "nyo", "rou", "unn", "onn" }; | ||
char syl_N[8][4] = { "kan", "ken", "san", "sin", "ten", "han", "gen", "jin" }; | ||
char syl_4[19][5] = { "iltu", "satu", "siki", "setu", "soku", "sowa", "toku", "noku", "hara", "metu", "yaku", "watu", "gyou", "shuu", "shou", "jitu", "chuu", "butu", "myou" }; | ||
char syl_5[6][6] = { "saltu", "toltu", "miltu", "zeltu", "bultu", "myaku" }; | ||
|
||
public: | ||
Chanting(const char* enter) { | ||
strcpy(enterCode, enter); | ||
} | ||
|
||
char* get() { | ||
// 終了している場合は改行のみを返す | ||
if (finished || cursor >= EEPROM.length()) return enterCode; | ||
|
||
// 現在のコードと1つ先のコードをEEPROMから取得 | ||
byte code = EEPROM.read(cursor); | ||
byte next = EEPROM.read(cursor + 1); | ||
cursor++; // 進めておく | ||
|
||
// 上位3ビットで音節配列選択・下位5ビットでインデックス選択 | ||
byte sylClass = code >> 5; | ||
byte sylIndex = code & 0x1F; | ||
switch (sylClass) { | ||
case 0: | ||
strcpy(output, syl_1[sylIndex]); | ||
break; | ||
case 1: | ||
strcpy(output, syl_2[sylIndex]); | ||
break; | ||
case 2: | ||
strcpy(output, syl_3[sylIndex]); | ||
break; | ||
case 3: | ||
strcpy(output, syl_N[sylIndex]); | ||
strcat(output, "n"); // ここだけnを付加する | ||
break; | ||
case 4: | ||
strcpy(output, syl_4[sylIndex]); | ||
break; | ||
case 5: | ||
strcpy(output, syl_5[sylIndex]); | ||
break; | ||
default: | ||
strcpy(output, ""); // 対応する音節配列がない | ||
} | ||
|
||
// 先読みしたコードが特殊操作(0xF0 ~ 0xFF)なとき | ||
if (next >= 0xF0) { | ||
if (next == 0xF0 || next == 0xFF) finished = true; | ||
if (next & 0x02) strcat(output, " "); // 0xF3はSPACE+ENTER | ||
if (next & 0x01) strcat(output, enterCode); | ||
cursor++; // もう1つ次に飛ばしておく(特殊コードは連続しない前提) | ||
} | ||
|
||
return output; | ||
} | ||
|
||
// インデックスを最初に戻す | ||
void reset() { | ||
cursor = 0; | ||
finished = false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* センサ接続に関する設定 SENSOR CONNECTIONS SETTING */ | ||
#define SDA 4 // 3軸加速度モジュール I2C SDA - Pro Micro D2 | ||
#define SCL 5 // 3軸加速度モジュール I2C SCL - Pro Micro D3 | ||
#define LED_NUM 5 // フルカラーLEDの個数(標準:5) | ||
#define LED_PIN 10 // フルカラーLED信号線 - Pro Micro D10 | ||
|
||
|
||
/* 読経モード CHANTING KEYBOARD MODE */ | ||
#define CHANT_KEYBOARD_ENTER "\n" // 読経時の改行扱い(Win/Mac/Linuxなど環境に応じて設定してください) | ||
#define UP_SPACE_SUPPORT false // 上入力でスペースキー入力して漢字変換をサポートするか | ||
#define DOWN_ENTER_SUPPORT false // 下入力でエンター入力して変換確定をサポートするか | ||
|
||
|
||
/* シリアルモード SERIAL OUTPUT MODE */ | ||
#define SERIAL_HIT_CODE '.' // 叩かれた時に送信するコード | ||
#define SERIAL_UP_CODE '^' // 上入力時に送信するコード | ||
#define SERIAL_LEFT_CODE '<' // 左入力時に送信するコード | ||
#define SERIAL_DOWN_CODE '_' // 下入力時に送信するコード | ||
#define SERIAL_RIGHT_CODE '>' // 右入力時に送信するコード | ||
|
||
|
||
/* MIDIモード MIDI DRUM MODE */ | ||
#define MIDI_CHANNEL 0 // MIDI送信するチャンネル | ||
#define MIDI_PITCH 60 // デフォルトの音階(標準ド: 60) | ||
#define AUTO_NOTEOFF_MAX 2000 // 次に叩かれなかったときに自動でノートオフするまでのミリ秒 | ||
|
||
|
||
/* キーボードモード GENERIC DIRECTION KEYBOARD MODE */ | ||
// 上下左右矢印 | ||
#define KEYBOARD_UP (KEY_UP_ARROW) | ||
#define KEYBOARD_LEFT (KEY_LEFT_ARROW) | ||
#define KEYBOARD_DOWN (KEY_DOWN_ARROW) | ||
#define KEYBOARD_RIGHT (KEY_RIGHT_ARROW) | ||
// WASDキーも使える | ||
//#define KEYBOARD_UP 'w' | ||
//#define KEYBOARD_LEFT 'a' | ||
//#define KEYBOARD_DOWN 's' | ||
//#define KEYBOARD_RIGHT 'd' | ||
|
||
|
||
/* ゲーミングモード GAMING MODE */ | ||
#define GAMING_UP 'w' | ||
#define GAMING_DOWN 's' | ||
|
||
|
||
/* キーボード・マウス・ゲーミング各モード 共通 COMMON SETTINGS FOR KEYBOARD & MOUSE & GAMING */ | ||
#define X_DIRECTION -1 // 1で左右正しい方向 | ||
#define Y_DIRECTION -1 // 1で上下正しい方向 | ||
|
||
|
||
/* 開発用(変更の必要ありません) FOR DEVELOPMENT */ | ||
#define RC_RATIO 0.2 | ||
#define STD_GRAVITY 9.80665f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* TaskLEDのキューにデータ送信して点灯制御する */ | ||
void FuncChangeLED(byte mode = 0, byte brightness = 0xFF) { | ||
static int message = 0; | ||
if (brightness < 10) brightness = 1; // 消灯は制御の都合により1にしておく(0だと処理をスキップするので消えない) | ||
message = (mode<<8) + brightness; | ||
xQueueSend(LEDQueue, &message, 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* 起動時にグラデーション表示するだけのやつ */ | ||
void FuncWelcomeLED() { | ||
delay(1000); | ||
float hue = 0.0; // 0.0 ~ 1.0 | ||
for (byte deg=0; deg<180; deg++) { | ||
float rad = (2 * PI / 360) * deg; | ||
// 虹色のところ: Hue,Saturation,Volume | ||
// 0.0625 = 4096/65536 | ||
for (int i=0; i<np.PixelCount(); i++) np.SetPixelColor(i, HsbColor(hue + (i * 0.0625), 1.0, sin(rad))); | ||
np.Show(); | ||
hue += 0.0078125; // = 512/65536 | ||
if (hue >= 1.0) hue -= 1.0; // ループ | ||
delay(30); | ||
} | ||
np.ClearTo(RgbColor(0, 0, 0)); | ||
np.Show(); | ||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,191 @@ | ||
# mokugyOS | ||
The operating system for USB connectable Mokugyo device. | ||
|
||
The operating system for USB connectable Mokugyo device. | ||
|
||
![](./img/demo.gif) | ||
|
||
日本語による解説は別途ブログで執筆中です。 | ||
|
||
## Hardware creation | ||
|
||
### 1. Requirements | ||
|
||
- Mokugyo | ||
Recommendation: [Amazon\.co\.jp: キクタニ 木魚 3寸 9cm TB\-9: 楽器](https://www.amazon.co.jp/gp/product/B0013PR1WQ/) | ||
- USB Standard-A(male) to Standard-A(male) cable | ||
- USB Standard-A(female) to Micro-B(male) short cable | ||
- Mallet (optional) | ||
- Small Zabuton (Japanese cushion, optional) | ||
- Microcontroller: [Pro Micro \- 5V/16MHz \- DEV\-12640 \- SparkFun Electronics](https://www.sparkfun.com/products/12640) | ||
- But you can choice any other ATmega32u4 based boards as main board, like [Arduino Micro](https://store.arduino.cc/usa/arduino-micro), [Arduino Leonardo](https://store.arduino.cc/usa/leonardo). | ||
- This README explains in case using Pro Micro. | ||
- Accelerometer: [Adafruit Triple\-Axis Accelerometer \- ±2/4/8g @ 14\-bit \- MMA8451 : ID 2019 : $7\.95 : Adafruit Industries, Unique & fun DIY electronics and kits](https://www.adafruit.com/product/2019) | ||
- Full-colored WS2812B compatible LED chip (5 pieces): [Adafruit NeoPixel Digital RGB LED Strip \- Black 60 LED \[BLACK\] : ID 1461 : $99\.80 : Adafruit Industries, Unique & fun DIY electronics and kits](https://www.adafruit.com/product/1461?length=1) | ||
- No need to buy Adafruit's LED because a bit expensive. Recommend NeoPixel compatible LED, like [フルカラーシリアルLEDモジュール \- SWITCH\-SCIENCE](https://www.switch-science.com/catalog/1398/), [NeoPixelフルカラーLEDテープ・5V版各種 – Shigezone Online](https://www.shigezone.com/?product=neopixel_ledtape5v), etc. | ||
- Only 5 pieces needed. | ||
- LED strip type is BEST, will helps making it simply. | ||
- Microphone (optional): [SparkFun Electret Microphone Breakout \- BOB\-12758 \- SparkFun Electronics](https://www.sparkfun.com/products/12758) | ||
|
||
![](./img/1.png) | ||
|
||
### 2. Drill a USB hole on Mokugyo | ||
|
||
![](./img/2.png) | ||
|
||
Make a square hole by drill and cutter. | ||
|
||
![](./img/3.png) | ||
|
||
Put large side of USB Standard-A(female) to Micro-B(male) short cable to this hole. | ||
|
||
### 3. Connect sensors and LEDs to microcontroller | ||
|
||
Pins assign: | ||
|
||
| Sensor's Pin | Pro Micro's Pin | | ||
|:--|:--| | ||
| MMA8451 VIN | VCC | | ||
| MMA8451 GND | GND | | ||
| MMA8451 SDA | 2 | | ||
| MMA8451 SCL | 3 | | ||
| LED strip +5V | VCC | | ||
| LED strip GND | GND | | ||
| LED strip Din | 10 | | ||
| Microphone VCC | VCC | | ||
| Microphone GND | GND | | ||
| Microphone AUD | A0 | | ||
|
||
Note: Current version of mokugyOS does not support microphone listening yet so implementing it is optional. | ||
|
||
![](./img/4.png) | ||
|
||
Do soldering to connect sensors to Pro Micro. | ||
|
||
![](./img/5.png) | ||
|
||
As for NeoPixel LED strip, cut 5 pixels and be careful about signal polarity at soldering (check Din pin's arrow sign direction on the strip). | ||
|
||
### 4. Put sensors&controller unit into Mokugyo | ||
|
||
![](./img/6.png) | ||
|
||
1. Stick LED strip on inner side of Mokugyo using double sided tape. | ||
2. Connect USB-MicroB connector to controller. | ||
3. Push sensors&controller into Mokugyo. | ||
|
||
![](./img/7.png) | ||
|
||
Look the 3-axis sign on MMA8451 and pay attension at placing this sensor. | ||
`Z-axis`: be parallel with hit direction by mallet. Z+ direction is vertically above. | ||
`Y-axis`: Y+ direction is facing Mokugyo mouth (groove) from central. | ||
|
||
## Software Installation | ||
|
||
### 1. Install Arduino IDE on your PC if not yet | ||
|
||
[Software \| Arduino](https://www.arduino.cc/en/software) | ||
|
||
### 2. Install board support library for Pro Micro | ||
|
||
Following instructions below: | ||
[sparkfun/Arduino\_Boards: Board definitions for SparkFun\-manufactured AVR, ARM, and ESP\-based Arduino boards\.](https://github.com/sparkfun/Arduino_Boards) | ||
|
||
![](./img/8.png) | ||
|
||
After board installation, please set options like above on Arduino IDE. | ||
**DO SELECT "ATmega32U4 (5V, 16 MHz)"**, not other one "(3.3V, 8 MHz)". | ||
|
||
### 3. Install dependencies | ||
|
||
Additional arduino libraries are below. | ||
Show the repositories here but all of them can be installed by arduino IDE built-in library manager. | ||
|
||
- FreeRTOS | ||
[feilipu/Arduino\_FreeRTOS\_Library: A FreeRTOS Library for all Arduino AVR Devices \(Uno, Leonardo, Mega, etc\)](https://github.com/feilipu/Arduino_FreeRTOS_Library) | ||
- NeoPixelBus by Makuna | ||
[Makuna/NeoPixelBus: An Arduino NeoPixel support library supporting a large variety of individually addressable LEDs\. Please refer to the Wiki for more details\. Please use the gitter channel to ask questions as the GitHub Issues feature is used for bug tracking\.](https://github.com/Makuna/NeoPixelBus) | ||
- MIDIUSB | ||
[arduino\-libraries/MIDIUSB: A MIDI library over USB, based on PluggableUSB](https://github.com/arduino-libraries/MIDIUSB) | ||
- Adafruit MMA8451 Library | ||
[adafruit/Adafruit\_MMA8451\_Library: Arduino library for the MMA8451 Accelerometer sensors in the Adafruit shop](https://github.com/adafruit/Adafruit_MMA8451_Library) | ||
- No need install [Adafruit Unified Sensor Driver](https://github.com/adafruit/Adafruit_Sensor). | ||
|
||
### 4. Writing sutra data into EEPROM | ||
|
||
**[ukkz/SutraWriter: EEPROM writer for mokugyOS\.](https://github.com/ukkz/SutraWriter)** | ||
|
||
1. Connect your Mokugyo to PC with USB cable. | ||
2. Clone or ZIP download ukkz/SutraWriter repository. | ||
3. Open `SutraWriter.ino` with Arduino IDE. | ||
4. Open Serial Monitor window, and then click upload button to write sketch into Mokugyo. | ||
5. SutraWriter runs immediately. Check Serial Monitor to verify EEPROM data like below: | ||
![](./img/9.png) | ||
|
||
### 5. Upload mokugyOS | ||
|
||
Clone or ZIP download this repository and upload to your Mokugyo. | ||
|
||
#### Configuration | ||
|
||
All configurable parameters are placed in `Config.h`. | ||
|
||
## How to use | ||
|
||
### Mode change | ||
|
||
![](./img/modechange.gif) | ||
|
||
Stand up and tilt left or right to change running mode. | ||
Lay down to run the selected mode. | ||
Default mode is "Chanting Keyboard". | ||
|
||
| LED color | Mode | | ||
|:--|:--| | ||
| Blue | Chanting Keyboard | | ||
| Yellow | Serial Commander | | ||
| Red | MIDI Instrument | | ||
| White | Generic Directional Pad | | ||
| Orange | Generic Mouse | | ||
| Mixed | Game Controller | | ||
|
||
About this color variants: [Buddhist flag \- Wikipedia](https://en.wikipedia.org/wiki/Buddhist_flag) | ||
|
||
### Chanting Keyboard Mode | ||
|
||
![](./img/demo-chanting.gif) | ||
|
||
Sends sutra phrase per beat as USB HID keyboard. | ||
|
||
### Serial Commander Mode | ||
|
||
![](./img/demo-serial.gif) | ||
|
||
Sends beating and 4-directional tilting command as USB Serial device. | ||
|
||
### MIDI Instrument Mode | ||
|
||
![](./img/demo-midi.gif) | ||
|
||
Sends Note-On and Note-Off messages as USB MIDI device. | ||
|
||
### Generic Directional Pad Mode | ||
|
||
![](./img/demo-dpad.gif) | ||
|
||
Sends beating (Enter key click) and 4-directional tilting (Arrow keys click) as USB HID keyboard. | ||
|
||
### Generic Mouse Mode | ||
|
||
![](./img/demo-mouse.gif) | ||
|
||
Sends beating (Mouse left click) and 4-directional tilting (Mouse cursor move) as USB HID mouse. | ||
|
||
### Game Controller Mode | ||
|
||
![](./img/demo-gaming.gif) | ||
|
||
Sends beating (Mouse left click), X-directional tilting (Horizontal mouse cursor move) and Y-directional tilting (`W` key or `S` key click) as USB HID keyboard & mouse. | ||
|
||
## LICENCE | ||
|
||
This project is licensed under the MIT License - see the LICENSE.md file for details. |
Oops, something went wrong.