C++ 如何修复arduino定序器总是输出

C++ 如何修复arduino定序器总是输出,c++,arrays,arduino,C++,Arrays,Arduino,我正在尝试编写一个我制作的Arduino节奏音序器,现在代码有问题,我使用LED作为输出。当我打开它时,所有的LED在每一节拍上都会闪烁,即使我的音符数组都设置为零。我在验证或上传代码时没有看到错误 const int outPins[4] = {3, 9, 10, 11}; //array of output pins int outState = 0; unsigned long previousMillis = 0; //stuff for "blink without del

我正在尝试编写一个我制作的Arduino节奏音序器,现在代码有问题,我使用LED作为输出。当我打开它时,所有的LED在每一节拍上都会闪烁,即使我的音符数组都设置为零。我在验证或上传代码时没有看到错误

const int outPins[4] = {3, 9, 10, 11};
//array of output pins

int outState = 0;
unsigned long previousMillis = 0;
//stuff for "blink without delay".
const int pot = A0;
//potentiometer/speed pin.
const int button = 7;
//button pin(not used yet).
int beats[4][16] = {{0}, {0}, {0}, {0}};
/*array of notes, first number(4) is the number of outputs.
 * second number(16) is the notes for each output. all notes should be set to "0" or off.
 */
int fast = 0;

void setup() {
  // put your setup code here, to run once:
pinMode(button, INPUT);
digitalWrite(button, HIGH);
}

void loop() {
  // put your main code here, to run repeatedly:
  fast = digitalRead(pot);
  fast = fast*100;
  
    unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= fast) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (outState == 0) {
      outState = 10;
    } else {
      outState = 0;
    }
    
    for (int j = 0; j < 16; j++)
    {
      for (int i = 0; i < 4; i++)
      {
        //for loop for every output and note.
        if (beats[i][j] = 1)
        //check if current note is on(ALL SOULD BE OFF).
        {
          analogWrite(outPins[i], outState);
          //turn on led/output.
        }
      }
    }
  }
}
const int outPins[4]={3,9,10,11};
//输出引脚阵列
int-outState=0;
无符号long-previousMillis=0;
//“毫不迟疑地眨眼”的素材。
常数int pot=A0;
//电位计/速度销。
常数int按钮=7;
//按钮销(尚未使用)。
int beats[4][16]={{0},{0},{0},{0};
/*注释数组,第一个数字(4)是输出的数量。
*第二个数字(16)是每个输出的注释。所有注释都应设置为“0”或关闭。
*/
int fast=0;
无效设置(){
//将安装代码放在此处,以便运行一次:
pinMode(按钮,输入);
数字写入(按钮,高);
}
void循环(){
//将主代码放在此处,以便重复运行:
快速=数字读取(pot);
快速=快速*100;
无符号长电流毫秒=毫秒();
如果(currentMillis-previousMillis>=快速){
//保存上次闪烁LED的时间
前一毫秒=当前毫秒;
//如果LED关闭,则将其打开,反之亦然:
如果(超出状态==0){
超出状态=10;
}否则{
超出状态=0;
}
对于(int j=0;j<16;j++)
{
对于(int i=0;i<4;i++)
{
//每个输出和注释的for循环。
如果(节拍[i][j]=1)
//检查当前备忘是否打开(所有备忘都应关闭)。
{
模拟写入(outPins[i],outState);
//打开led/输出。
}
}
}
}
}

如果(beats[i][j]=1)
是赋值。你想要
if(beats[i][j]==1)

除了下面的答案,你为什么要使用
analogWrite
激活LED?正确缩进代码。@我使用模拟写入,所以我不必在每个LED上焊接电阻。这是一个难以置信的坏主意。代码中的任何错误都可能导致电流过大,导致LED灯烧坏,甚至引脚烧坏。不要这样做。