目前我正在嘗試使用sparkfun promicro隨意使用此草圖https://www.sparkfun.com/tutorials/338來控制RX引腳。在leonardo中有沒有一種清除USBCore RX控制的乾淨方法?
但是,我遇到了一個問題,儘管控制了RX和TX,但它受到了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。然而,這樣做的做法很糟糕。