Midi控制器无法添加多个电位器
Unable to add multiple potentiometer in Midi controller
我正在构建一个简单的基于 arduino 的 midi 控制器来发送 cc midi 消息,但是我只能通过 A0(模拟输入)发送消息。
如有任何帮助,我们将不胜感激。
#include <MIDI.h>
int pot[] = {A0,A1,A2};
int AnaPinsNum = 3;
int potIn[] = {0,0,0};
int analogValue = 0;
int lastAnalogValue[] = {0,0,0};
void setup()
{
MIDI.begin(4);
// 115200 hairless MIDI
Serial.begin(115200);
int i;
for (i = 0; i < 3; i++);
}
void loop() {
int i;
for (i = 0; i < AnaPinsNum; i++)
potIn[i] = analogRead(pot[i])/8;
// potentiometer could be too sensitive and
// give different (+-1) values.
// send CC only when the difference between last value
// is more than 1
if ((potIn[i]-lastAnalogValue[i]) > 1 || (potIn[i]-lastAnalogValue[i]) < -1) {
// value changed?
if (potIn[i] != lastAnalogValue[i]) {
// send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
// more info: http://arduinomidilib.sourceforge.net/a00001.html
MIDI.sendControlChange(1, potIn[i], 1);
lastAnalogValue[i] = potIn[i];
}
}
}
此代码格式不正确。
如果您使用了自动缩进代码的编辑器,它看起来像这样:
for (i = 0; i < AnaPinsNum; i++)
potIn[i] = analogRead(pot[i])/8;
// potentiometer could be too sensitive and ...
if ((potIn[i]-...) {
换句话说,for
循环只有一行;循环结束后执行以下所有行,并且 i
的值为 3.
你忘记了循环体周围的大括号。
我正在构建一个简单的基于 arduino 的 midi 控制器来发送 cc midi 消息,但是我只能通过 A0(模拟输入)发送消息。
如有任何帮助,我们将不胜感激。
#include <MIDI.h>
int pot[] = {A0,A1,A2};
int AnaPinsNum = 3;
int potIn[] = {0,0,0};
int analogValue = 0;
int lastAnalogValue[] = {0,0,0};
void setup()
{
MIDI.begin(4);
// 115200 hairless MIDI
Serial.begin(115200);
int i;
for (i = 0; i < 3; i++);
}
void loop() {
int i;
for (i = 0; i < AnaPinsNum; i++)
potIn[i] = analogRead(pot[i])/8;
// potentiometer could be too sensitive and
// give different (+-1) values.
// send CC only when the difference between last value
// is more than 1
if ((potIn[i]-lastAnalogValue[i]) > 1 || (potIn[i]-lastAnalogValue[i]) < -1) {
// value changed?
if (potIn[i] != lastAnalogValue[i]) {
// send serial value (ControlNumber 1, ControlValue = analogValue, Channel 1)
// more info: http://arduinomidilib.sourceforge.net/a00001.html
MIDI.sendControlChange(1, potIn[i], 1);
lastAnalogValue[i] = potIn[i];
}
}
}
此代码格式不正确。
如果您使用了自动缩进代码的编辑器,它看起来像这样:
for (i = 0; i < AnaPinsNum; i++)
potIn[i] = analogRead(pot[i])/8;
// potentiometer could be too sensitive and ...
if ((potIn[i]-...) {
换句话说,for
循环只有一行;循环结束后执行以下所有行,并且 i
的值为 3.
你忘记了循环体周围的大括号。