我正在一個項目中,我需要9個7段顯示器。我爲此使用了9個移位寄存器。無法更新與NodeMCU的移位寄存器
我用Arduino Nano測試了移位寄存器,並且一切正常。然後,我複製/編輯了代碼,用於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具有更高的時鐘頻率。所以我試圖加入延遲。但它沒有奏效。
當您運行代碼時,您在節點mcu上收到的輸出是什麼? – Billa
只是:測試!!!!!該程序編譯並運行良好。 – oedze
接受和upvote答案,如果你認爲它應該有一個在將來有類似的疑問 – Billa