硬件串口写入arduino

Hardware serial write arduino

本文关键字:arduino 串口 硬件      更新时间:2023-10-16

我正在尝试使用NANO写入串行。这是我当前的代码

#include "HardwareSerial.h"
long previousMillis = 0;
long interval = 2000;    
void setup() {
  // put your setup code here, to run once:
 pinMode(13, OUTPUT);
 digitalWrite(13, HIGH);
 Serial.begin(9600);
}
void loop() {
  // put your main code here, to run repeatedly:
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis; 
    HardwareSerial serial = Serial;
    serial.write("hello");
  }
}

然而,当我使用串行监视器监视串行时,我只得到

用于每次串行写入。请帮助

我已经将我的方法中的类类型从hardwareserial更改为stream &serial,现在它应该以这种方式工作。谢谢你的帮助