我对编码完全陌生,这甚至是我在这里的第一篇文章。我尝试这样做是因为没有人出售我想要/需要的东西;-)。
我已经取得了相当大的成就,但此刻我迷失了很多东西(我在过去的 8 天里阅读了很多关于编码的内容,特别是关于 Arduino 的内容)......但让我先解释一下我的这个项目的意图是:
我想构建一个“Stomp Box”来静音Behringer X32 Rack (wireless) Channels/Mutegroups/Buses,只是静音开/关..没有别的。
这个盒子应该有 4-6 个“stompers”(按钮),每个按钮都应该有不同的静音功能。
此外,如果未静音,则通道/静音组/总线的当前状态应由 LED 指示为绿色,如果静音则为红色。
因此盒子需要评估指定通道/静音组/总线的当前状态,因为它也可能从其他远程设备更改。
然后在按下/踩踏指定按钮时切换到相反状态。
我想要有可以轻松更改按钮操作的代码,例如:
button1 = /ch/01/mix/on ,i 1
button2 = /config/mute/1 ,i 1
按钮 3 = /dca/1/on ,i 1
所以如果我需要一个不同的通道/静音组/总线来进行另一个事件,只需编辑和重新编码我的ESP32 节点套件
所以这是我已经拥有的代码:
#include "WiFi.h"
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <SPI.h>
#include <OSCMessage.h> //https://github.com/CNMAT/OSC
#define WIFI_NETWORK "xxxxxxxxxx" //SSID of you Wifi
#define WIFI_PASSWORD "xxxxxxxxxxx" //Your Wifi Password
#define WIFI_TIMEOUT_MS 20000 // 20 second WiFi connection timeout
#define WIFI_RECOVER_TIME_MS 30000 // Wait 30 seconds after a failed connection attempt
int muteOn = 0;// 0=Mute
int muteOff = 1;// 1=Unmute
int input;
WiFiUDP Udp;
const IPAddress outIp (192, 168, 10, 129); //Mixers IP
const unsigned int outPort = 10023; //X32 Port
//variables for blinking an LED with Millis
const int led = 2; // ESP32 Pin to which onboard LED is connected
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 300; // interval at which to blink (milliseconds)
int ledState = LOW; // ledState used to set the LED
void connectToWiFi(){
Serial.print("Zu WLAN verbinden...");
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_NETWORK, WIFI_PASSWORD);
unsigned long startAttemptTime = millis();
while(WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < WIFI_TIMEOUT_MS){
Serial.println(".");
delay(100);
}
if(WiFi.status() != WL_CONNECTED){
Serial.println("Nicht Verbunden!");
//optional take action
}else{
Serial.print("WLAN Verbunden mit ");
Serial.println(WIFI_NETWORK);
Serial.println(WiFi.localIP( ));
}
}
void setup() {
Serial.begin(115200);
connectToWiFi();
Udp.begin(8888);
pinMode(led, OUTPUT);
// Port defaults to 3232
// ArduinoOTA.setPort(3232);
// Hostname defaults to esp3232-[MAC]
// ArduinoOTA.setHostname("myesp32");
// No authentication by default
// ArduinoOTA.setPassword("admin");
// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
ArduinoOTA
.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
})
.onEnd([]() {
Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop(){
ArduinoOTA.handle();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
ledState = not(ledState);
// set the LED with the ledState of the variable:
digitalWrite(led, ledState);
}
input=Serial.read();
if (input=='0'){
// welcher status hat der kanal?
// wenn Kanal gemutet dann unmute und umgekehrt
Serial.println("Mute!");
delay(100);
sendMute(); //send Mute to Mixer
Serial.println("...");
}
if (input=='1'){
Serial.println("UnMute!");
delay(100);
sendUnMute();
Serial.println("...");
}
}
void sendMute() {
//the message wants an OSC address as first argument
OSCMessage msg("/ch/01/mix/on");
msg.add(muteOn);
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
delay(20);
}
void sendUnMute() {
//the message wants an OSC address as first argument
OSCMessage msg("/ch/01/mix/on");
msg.add(muteOff);
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
delay(20);
}
因此,我通过串行监视器对此进行了测试,当我输入“0”并单击发送时,混音器将通道 1 静音,并且在输入“1”时,通道 1 变为未静音,到目前为止一切都很好(OSCMessage msg("/ch/01/mix/on");
......部分。
特别困扰我的是,我不得不硬编码命令“/ch/01/mix/on”,因为我无法声明变量?对于这个字符串?我已经很困惑了,我什至不知道我是否有正确的条款:-(
顺便说一句:有很多解决方案如何使用 MIDI 来实现,但 MIDI 不是无线的,我认为我的项目有点矫枉过正。我还在github.com/CNMAT/OSC上做了一些研究,但我不明白......(哭泣)......我在这里
也找到了一个帖子,但这也没有帮助...... :-(
关于如何实现目标的任何建议?-
任何帮助都非常受欢迎......即使是德语(我的母语......)
PS:是的,我是初学者,我承认。但至少在过去的 8 天里,我设法通过 OTA 连接和刷写这个东西,所以请放轻松。