无法使用 NodeMCU 更新移位寄存器

Unable to update shift register with NodeMCU

我正在做一个需要 9 个 7 段显示器的项目。我为此使用了 9 个移位寄存器。

我用 Arduino Nano 测试了移位寄存器,一切正常。然后我 copied/edited 在 NodeMCU(ESP8266 wifi 板)中使用的代码,由于某种原因,写入移位寄存器的功能似乎被破坏了。

现在是代码:

void writeBytes(uint8_t bytesToWrite[]){
  Serial.println("test!!!");
  //Run through the 9 bytes in bytes to write.
  for(int q = 0; q < 9; q++) {
    //Loop through the 8 bits.
    for(int i =0; i < 8; i++) {
      //Check if the msb = 1
      if(0x80 & bytesToWrite[q]) {
        digitalWrite(dataPin, HIGH);
        delay(delayTime);
        digitalWrite(clockPin, HIGH);
        delay(delayTime);
        digitalWrite(clockPin, LOW);
        delay(delayTime);
        digitalWrite(dataPin, LOW);
        delay(delayTime);
      } else {
        digitalWrite(clockPin, HIGH);
        delay(delayTime);
        digitalWrite(clockPin, LOW);
        delay(delayTime);
      }
      //Shift all the bits one up.
      bytesToWrite[q] = bytesToWrite[q] << 1;
    }
  }
  //Turn on the out pin, so it will output.
  digitalWrite(outPin, HIGH);
  delay(delayTime);;
  digitalWrite(outPin, LOW);
  delay(delayTime);
}

我检查了我是否使用了正确的引脚并检查了这些引脚是否真的打开了。我还检查了该函数是否会被执行以及是否会传递正确的变量并且确实如此。

同样的功能适用于 Arduino Nano。但它不适用于 NodeMCU。 NodeMCU 具有更高的时钟频率。所以我尝试添加延迟。但它没有用。

错误可能是因为:

  1. 可能是你复制代码的时候出错了。
  2. 或者你没有粘贴正确。
  3. 一些编辑也可能会产生同样的效果。
  4. 可能是硬件问题,接触不良等

(你应该尽可能避免使用延迟,因为开发人员说使用它们会带来开销,我认为你应该注意它)。

NodeMCU 上的引脚号与数据表上的引脚号不匹配。 可以在此处找到正确的引脚号: https://github.com/esp8266/Arduino/issues/584