Shinya Ishikawa
A software engineer on the middle of a long journey for Human-Machine Interface: from Web Frontend to Real Robots! M5Stack lover.
https://github.com/meganetaaan/m5stack-avatar
https://github.com/meganetaaan/m5stack-theremin
寝る子も泣き出すM5Stack
M5Stackの音量を抵抗1つで調節する | N.Yamazaki's blog
http://blog-yama.a-quest.com/?eid=970193
// 現在 M5.Speaker.playMusic()でのみ有効
// https://github.com/m5stack/M5Stack/blob/master/src/utility/Speaker.cpp
M5.Speaker.setVolume(1);
候補a) Speaker.setVolume ... Speaker.toneには効かない
候補b) MQTTを使う
MQTT
Broker
MQTT
Client
(Sub)
MQTT
Client
(Pub)
frequency: 440.0
Client
(Pub)
Broker
Client
(Sub)
const mosca = require('mosca')
const ascoltatore = {
//using ascoltatore
type: 'mongo',
url: 'mongodb://localhost:27017/mqtt',
pubsubCollection: 'ascoltatori',
mongo: {}
}
const settings = {
port: 1883,
backend: ascoltatore,
http: {
port: 8080,
bundle: true,
static: './public'
}
}
const server = new mosca.Server(settings)
$ npm init -y
$ npm install -S mosca
https://github.com/mcollina/mosca
Client
(Pub)
Broker
Client
(Sub)
#include <WiFi.h>
#include <WiFiClient.h>
#include <PubSubClient.h>
#include <M5Stack.h>
#include "const.h"
WiFiClient httpsClient;
PubSubClient mqttClient(httpsClient);
boolean isPub = true;
void setup()
{
M5.begin();
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);
M5.Speaker.setVolume(1);
M5.Speaker.update();
setupWifi();
}
// 中略
void loop()
{
M5.update();
updateEcho();
Duration = pulseIn(echoPin, HIGH); //センサからの入力
if (Duration > 0)
{
Distance = getDistance(Duration); // 反応時間から距離を計算
float f = getNote(Distance); // 距離から音程を計算
if (isPub)
{
publishFreq(f);
}
else
{
M5.Speaker.tone(f);
}
}
delay(125);
}
※https://www.1ft-seabass.jp/memo/2018/05/10/m5stack-meets-nodered-with-mqtt/
const mosca = require('mosca')
const ascoltatore = {
//using ascoltatore
type: 'mongo',
url: 'mongodb://localhost:27017/mqtt',
pubsubCollection: 'ascoltatori',
mongo: {}
}
const settings = {
port: 1883,
backend: ascoltatore,
http: {
port: 8080,
bundle: true,
static: './public'
}
}
const server = new mosca.Server(settings)
Client
(Pub)
Broker
Client
(Sub)
https://www.html5rocks.com/ja/tutorials/webaudio/intro/
By Shinya Ishikawa
ジュゥゥゥワワン!!
A software engineer on the middle of a long journey for Human-Machine Interface: from Web Frontend to Real Robots! M5Stack lover.