程序不适用于arduino leonardo
我有一个程序,可以在一个带有串行输出的uno上运行,但不能在莱昂纳多上运行,唯一的变化是键盘的按下和释放。我使用的是硬币机械,当硬币被添加时,它会输出一个脉冲。然而,当电缆从发送信号的引脚上松脱时,它确实触发了多次负载程序不适用于arduino leonardo,arduino,Arduino,我有一个程序,可以在一个带有串行输出的uno上运行,但不能在莱昂纳多上运行,唯一的变化是键盘的按下和释放。我使用的是硬币机械,当硬币被添加时,它会输出一个脉冲。然而,当电缆从发送信号的引脚上松脱时,它确实触发了多次负载 const int coinInt = 0; //Attach coinInt to Interrupt Pin 0 (Digital Pin 2). Pin 3 = Interrpt Pin 1. volatile float coinsValue = 0.00;
const int coinInt = 0;
//Attach coinInt to Interrupt Pin 0 (Digital Pin 2). Pin 3 = Interrpt Pin 1.
volatile float coinsValue = 0.00;
//Set the coinsValue to a Volatile float
//Volatile as this variable changes any time the Interrupt is triggered
int coinsChange = 0;
//A Coin has been inserted flag
void setup()
{
attachInterrupt(coinInt, coinInserted, RISING);
//If coinInt goes HIGH (a Pulse), call the coinInserted function
//An attachInterrupt will always trigger, even if your using delays
}
void coinInserted()
//The function that is called every time it recieves a pulse
{
coinsValue = coinsValue + 0.05;
//As we set the Pulse to represent 5p or 5c we add this to the coinsValue
coinsChange = 1;
//Flag that there has been a coin inserted
}
void loop()
{
if(coinsChange == 1)
//Check if a coin has been Inserted
{
coinsChange = 0;
//unflag that a coin has been inserted
Keyboard.press('+');
delay(100);
Keyboard.releaseAll();
//Print the Value of coins inserted
}
}
这可能不是问题所在,但我看到coinsChanged在中断函数中设置,并在loop()中测试,但没有声明为volatile 我要换衣服
int coinsChange = 0;
到
volatile int coinsChange = 0;