简体   繁体   English

如何修复 arduino 定序器始终输出

[英]How to fix arduino sequencer always outputting

I'm trying to code an Arduino rhythm sequencer I made, and there's a problem with the code right now, im using LEDs as outputs.我正在尝试编写我制作的 Arduino 节奏音序器,现在代码有问题,我使用 LED 作为输出。 When I turn it on, all of the LEDs blink on every beat, even though I have the array of notes all set to zero.当我打开它时,所有的 LED 都会在每个节拍上闪烁,即使我将音符阵列全部设置为零。 I see no errors when verifying or uploading the code.验证或上传代码时,我没有看到任何错误。

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.
        }
      }
    }
  }
}

if (beats[i][j] = 1) is assignment. if (beats[i][j] = 1)是赋值。 You wanted if (beats[i][j] == 1)你想要if (beats[i][j] == 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM