○パーツリスト
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
抵抗20kΩ
|
1
|
M2タッピングネジ
|
2
|
その他、配線用ワイヤー、ホットボンドなど。
○回路図
○配線・レイアウト
○制御用プログラム
・Androidアプリ
・Androidアプリ
こちらから、apkファイルをダウンロードして、インストールしてください。
MIT App Inventorのプロジェクトファイルは、こちらからダウンロードできます。
・PC(Node.js)
必要モジュール soket.io、serialport
次のHTMLとJavaScriptコードを入力し、作業用フォルダに保存します。
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
<!DOCTYPE HTML> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>MP3 TEST</title> | |
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script> | |
</head> | |
<body> | |
<script> | |
var socket = io(); | |
function play() { | |
socket.emit('msg', 'play'); | |
} | |
function pause() { | |
socket.emit('msg', 'pause'); | |
} | |
function resume() { | |
socket.emit('msg', 'resume'); | |
} | |
function prev() { | |
socket.emit('msg', 'prev'); | |
} | |
function next() { | |
socket.emit('msg', 'next'); | |
} | |
function up() { | |
socket.emit('msg', 'up'); | |
} | |
function down() { | |
socket.emit('msg', 'down'); | |
} | |
function loop() { | |
socket.emit('msg', 'loop'); | |
} | |
function seteq() { | |
socket.emit('msg', 'eq'); | |
} | |
function repon() { | |
socket.emit('msg', 'repon'); | |
} | |
function repoff() { | |
socket.emit('msg', 'repoff'); | |
} | |
</script> | |
<form> | |
<input type="button" value="PLAY" onclick="play()"/> | |
<input type="button" value="PAUSE" onclick="pause()"/> | |
<input type="button" value="RESUME" onclick="resume()"/> | |
<input type="button" value="<<" onclick="prev()"/> | |
<input type="button" value=">>" onclick="next()"/> | |
<input type="button" value="Vol Down" onclick="down()"/> | |
<input type="button" value="Vol Up" onclick="up()"/> | |
<input type="button" value="LOOP" onclick="loop()"/> | |
<input type="button" value="EQ" onclick="seteq()"/> | |
<input type="button" value="REP ON" onclick="repon()"/> | |
<input type="button" value="REP OFF" onclick="repoff()"/> | |
</form> | |
</body> | |
</html> |
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
var serialport = require('serialport'); | |
var port = new serialport.SerialPort( | |
'COM6', { | |
baudrate: 9600, | |
parser: serialport.parsers.readline('\r\n') | |
} | |
); | |
var html = require('fs').readFileSync('index.html'); | |
var http = require('http').createServer(function(req, res) { | |
res.writeHead(200, { | |
'Content-Type': 'text/html' | |
}); | |
res.end(html); | |
}); | |
var io = require('socket.io')(http); | |
http.listen(3000); | |
var eqmode = 0; | |
port.on('open', function () { | |
SelectPlayerDevice(0x02); | |
SetVolume(1); | |
SetEQ(0); | |
io.on('connection', function(socket) { | |
socket.on('msg', function(data) { | |
console.log(data); | |
if(data == "play"){ | |
SpecifyMusicPlay(1); | |
} | |
if(data == "pause"){ | |
PlayPause(); | |
} | |
if(data == "resume"){ | |
PlayResume(); | |
} | |
if(data == "prev"){ | |
PlayPrevious(); | |
} | |
if(data == "next"){ | |
PlayNext(); | |
} | |
if(data == "loop"){ | |
PlayLoop(); | |
} | |
if(data == "down"){ | |
DecreaseVolume(); | |
} | |
if(data == "up"){ | |
IncreaseVolume(); | |
} | |
if(data == "repon"){ | |
StartRepeat(); | |
} | |
if(data == "repoff"){ | |
StopRepeat(); | |
} | |
if(data == "eq"){ | |
eqmode ++; | |
if (eqmode > 5) eqmode = 0; | |
SetEQ(eqmode); | |
} | |
}); | |
}); | |
}); | |
function SelectPlayerDevice(device) { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x09,0x00,0,device,0xEF]); | |
setTimeout(port.write(buf),100); | |
} | |
function SpecifyMusicPlay(index) { | |
var hbyte = parseInt(index / 256); | |
var lbyte = parseInt(index % 256); | |
var buf = new Buffer([0x7E,0xFF,0x06,0x03,0x00,hbyte,lbyte,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function PlayPause() { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x0E,0x00,0x00,0x00,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function PlayResume() { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x0D,0x00,0x00,0x00,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function PlayNext() { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x01,0x00,0x00,0x00,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function PlayPrevious() { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x02,0x00,0x00,0x00,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function PlayLoop() { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x11,0x00,0x00,0x01,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function SetVolume(volume) { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x06,0x00,0x00,volume,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function IncreaseVolume() { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x04,0x00,0x00,0x00,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function DecreaseVolume() { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x05,0x00,0x00,0x00,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function StartRepeat() { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x19,0x00,0x00,0x00,0xFE,0xE2,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function StopRepeat() { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x19,0x00,0x00,0x01,0xFE,0xE1,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} | |
function SetEQ(mode) { | |
var buf = new Buffer([0x7E,0xFF,0x06,0x07,0x00,0x00,mode,0xEF]); | |
setTimeout(port.write(buf),1000); | |
} |
PC(Windows)とbluetoothモジュールのペアリング、COMポートの確認方法は、「IchigoJamとPCの通信をBluetoothで無線化する」を参照してください。
以下の手順で動作を確認します。
①コマンドプロンプトを起動し、作業用フォルダに移動します。
②「node mp3.js」と入力します。
③ブラウザで「http://localhost:3000」にアクセスします。
④各ボタンをクリックし、動作を確認します。
○参考
ケースの3Dプリントのデータは、こちらからダウンロードできます。
0 件のコメント:
コメントを投稿