| 7 | * Bluetoothモジュール RN-42-I/RM x 1 |
| 8 | * 測距モジュール GP2Y0E02A(アナログ出力) x 1 |
| 9 | * 3.3V出力DCDCコンバータ x 1 |
| 10 | * 蛇の目基板 x 1 |
| 11 | * 電池ボックス 単4×1本用 x 2 |
| 12 | * ICソケット x 1 |
| 13 | * 電解コンデンサ x 1 |
| 14 | * 抵抗 x 1 |
| 15 | * 単4形アルカリ乾電池 x 2 |
| 16 | * [https://www.switch-science.com/catalog/1414/ Arduinoブートローダ書き込み済みATMega328P-PU(内蔵CR発振8MHz版)] x 1 |
| 17 | |
| 18 | これらの部品は[https://www.switch-science.com/catalog/2248/ ピロピロインターフェース 電子部品キット]に含まれています。 |
| 19 | |
| 20 | 3. 回路を組み立てる |
| 21 | 以下の実体配線図と同じ回路を蛇の目基板上に組み立ててください。 |
| 22 | |
| 23 | 4. Bluetoothモジュールの設定をする |
| 24 | * Bluetoothモジュールを[https://www.switch-science.com/catalog/1534/ USBシリアル変換アダプタ]などでパソコンと接続してください。 |
| 25 | * シリアルコンソールを開いて、"$$$"と打ち込んで"CMD"と返ってきたら、以下のコマンドを打ち込んでください。 |
| 26 | {{{ |
| 27 | SU,115k |
| 28 | SM,6 |
| 29 | SA,2 |
| 30 | S~,6 |
| 31 | SH,0000 |
| 32 | SN,MY_PIROPIRO_KEYBOARD |
| 33 | R,1 |
| 34 | }}} |
| 35 | |
| 36 | 5. ATmega328にスケッチを書き込む |
| 37 | Arduino UNOなどを使って、ATmega328にスケッチを書き込んでください。そのときにボードの設定はArduino Pro or Pro Mini, ATmega328(3.3V, 8MHz)を選んでください。 |
| 38 | [https://github.com/googlei18n/mozc-devices/blob/master/mozc-piropiro/arduino/piropiro/piropiro.ino スケッチ] |
| 39 | |
| 40 | {{{ |
| 41 | /* |
| 42 | * Copyright 2015 Google Inc. |
| 43 | * |
| 44 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 45 | * you may not use this file except in compliance with the License. |
| 46 | * You may obtain a copy of the License at |
| 47 | * |
| 48 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 49 | * |
| 50 | * Unless required by applicable law or agreed to in writing, software |
| 51 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 52 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 53 | * See the License for the specific language governing permissions and |
| 54 | * limitations under the License. |
| 55 | */ |
| 56 | |
| 57 | /* |
| 58 | * Firmware of piropiro (party horn) Bluetooth keyboard. |
| 59 | */ |
| 60 | |
| 61 | #define V_REF 5.0 |
| 62 | #define PIN_LED 13 |
| 63 | #define N_AD_SAMPLES 10 |
| 64 | |
| 65 | #define INTERVAL_MSEC 20 |
| 66 | #define COMMIT_TIME (600 / INTERVAL_MSEC) |
| 67 | |
| 68 | #define ROWS 5 |
| 69 | #define COLS 10 |
| 70 | |
| 71 | const char* characters[ROWS * COLS] = { |
| 72 | "a", "i", "u", "e", "o", |
| 73 | "ka", "ki", "ku", "ke", "ko", |
| 74 | "sa", "si", "su", "se", "so", |
| 75 | "ta", "ti", "tu", "te", "to", |
| 76 | "na", "ni", "nu", "ne", "no", |
| 77 | "ha", "hi", "hu", "he", "ho", |
| 78 | "ma", "mi", "mu", "me", "mo", |
| 79 | "ya", "ya", "yu", "yu", "yo", |
| 80 | "ra", "ri", "ru", "re", "ro", |
| 81 | "wa", "wo", "nn", ",", "." |
| 82 | }; |
| 83 | |
| 84 | int column = 0; |
| 85 | int vowel = 0; |
| 86 | int release_duration = 0; |
| 87 | |
| 88 | void setup() { |
| 89 | Serial.begin(115200); |
| 90 | pinMode(PIN_LED, OUTPUT); |
| 91 | column = 0; |
| 92 | vowel = 0; |
| 93 | } |
| 94 | |
| 95 | float getVoltage(int ch) { |
| 96 | return analogRead(ch) * V_REF / 1023; |
| 97 | } |
| 98 | |
| 99 | float getAverageVoltage(int ch) { |
| 100 | float sum = 0.0; |
| 101 | for (int i = 0; i < N_AD_SAMPLES; i++) { |
| 102 | sum += getVoltage(ch); |
| 103 | } |
| 104 | return sum / N_AD_SAMPLES; |
| 105 | } |
| 106 | |
| 107 | float voltageToLength(float voltage) { |
| 108 | return 648 - voltage * 268; |
| 109 | } |
| 110 | |
| 111 | void loop() { |
| 112 | float length = voltageToLength(getAverageVoltage(0)); |
| 113 | if (length > 350) { |
| 114 | digitalWrite(PIN_LED, LOW); |
| 115 | } else { |
| 116 | digitalWrite(PIN_LED, HIGH); |
| 117 | if (length < 50) { |
| 118 | if (vowel > 0) { |
| 119 | vowel = 0; |
| 120 | column ++; |
| 121 | if (column >= COLS) { |
| 122 | column = 0; |
| 123 | } |
| 124 | release_duration = 0; |
| 125 | } else if (release_duration > COMMIT_TIME) { |
| 126 | vowel = 0; |
| 127 | column = 0; |
| 128 | } else if (column > 0) { |
| 129 | release_duration ++; |
| 130 | } |
| 131 | } else { |
| 132 | int target_vowel = (length - 80) / 40 + 1; |
| 133 | if (target_vowel > 5) target_vowel = 5; |
| 134 | if (vowel < target_vowel) { |
| 135 | if (column > 0 || vowel > 0) { |
| 136 | Serial.print("\b"); |
| 137 | } |
| 138 | vowel ++; |
| 139 | int current_character = vowel - 1 + column * 5; |
| 140 | Serial.print(characters[current_character]); |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | delay(INTERVAL_MSEC); |
| 145 | } |
| 146 | }}} |
| 147 | |
| 148 | 6. 3Dプリンタで固定用部品を出力します。 |
| 149 | [https://www.switch-science.com/catalog/list/571/ Makerbot]などの3Dプリンタで部品を出力します。 |
| 150 | |
| 151 | [https://github.com/googlei18n/mozc-devices/tree/master/mozc-piropiro/stl 各部品のSTLファイル] |
| 152 | |
| 153 | 7.ピロピロに各部品をくっつけたら完成です。手持ちのスマートフォンとペアリングして遊んでみてください。 |