你好 StackOverflow 社区,
我无法锁定红外遥控器发出的“向上”和“向下”信号。在测试时,我发现我通过 UP 和 Down 命令收到了数字 18 和 52,所以我将这些值转换为 HEX。这样我就可以创建一个定义了两种情况的 if 语句。
到目前为止,这是我的程序:
`#include <Stepper.h>
#include <IRremote.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048
int Steps2Take;
const int RECV_PIN = 7;
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
//-------------------------------------------------------------
//The pin connections need to be pins 8,9,10,11 connected
// to Motor Driver In1, In2, In3, In4
//-------------------------------------------------------------
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
void setup() /*----( SETUP: RUNS ONCE )----*/
{
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK);
}
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
if (IrReceiver.decode())
{
switch(IrReceiver.decodedIRData.command, HEX)
{
case 0x12:
Steps2Take = STEPS_PER_OUTPUT_REVOLUTION ; // Rotate CW 1 turn
small_stepper.setSpeed(700);
small_stepper.step(Steps2Take);
delay(500);
}
IrReceiver.resume();
}
}`
运行时,只有红外传感器和 Arduino 闪烁,而步进电机什么都不做。
到目前为止,我已经尝试用新的 IrSensor 库重写程序,看看它是否只是不推荐使用的包导致的。事实证明,事实并非如此。
如有任何帮助,我们将不胜感激。