目前,我正在尝试使用 sparkfun promicro 使用此草图https://www.sparkfun.com/tutorials/338随意控制 RX 引脚。
但是我遇到了一个问题,尽管可以控制 RX 和 TX led,但它还是受到了 arduino 中的 USBCore.cpp 的干扰。我想知道是否有一种干净的方法可以禁用 USBCore 对 RX 和 TX 引脚的控制,同时仍然不理会 USB 串行,这样我就可以直接控制这些引脚,即使在接收和发送串行数据时也是如此。
/* Pro Micro Test Code
by: Nathan Seidle
modified by: Jim Lindblom
SparkFun Electronics
date: January 20, 2012
license: Public Domain - please use this code however you'd like.
It's provided as a learning tool.
This code is provided to show how to control the SparkFun
ProMicro's TX and RX LEDs within a sketch. It also serves
to explain the difference between Serial.print() and
Serial1.print().
*/
int RXLED = 17; // The RX LED has a defined Arduino pin
// The TX LED was not so lucky, we'll need to use pre-defined
// macros (TXLED1, TXLED0) to control that.
void setup()
{
pinMode(RXLED, OUTPUT); // Set RX LED as an output
// TX LED is set as an output behind the scenes
Serial.begin(9600); //This pipes to the serial monitor
Serial1.begin(9600); //This is the UART, pipes to sensors attached to board
}
void loop()
{
Serial.println("Hello world"); // Print "Hello World" to the Serial Monitor
Serial1.println("Hello!"); // Print "Hello!" over hardware UART
digitalWrite(RXLED, HIGH); // set the LED on
TXLED1; //TX LED is not tied to a normally controlled pin
delay(1000); // wait for a second
digitalWrite(RXLED, LOW); // set the LED off
TXLED0;
delay(1000); // wait for a second
}
如果不修改 arduino 环境就无法干净地解决这个问题,那么我将修改 USBCore.cpp 。然而,这样做可能是不好的做法。