[英]Infrared not returning 1 as correct value
我正在尝试创建一个手套,当你向下转动手腕时,它会发送 1 作为 IR 信号,如果你向上转动手腕,它会为我使用的手套返回 0 javascript:
input.onGesture(Gesture.TiltDown, function () {
music.playMelody("E B C5 A B G A F ", 262)
network.infraredSendNumber(1)
light.showRing(
`blue red blue red blue blue red blue red blue`)
})
input.onGesture(Gesture.TiltUp, function () {
music.wawawawaa.play()
network.infraredSendNumber(0)
light.showAnimation(light.cometAnimation, 500)
})
我不相信那里有问题,但是当我 go 到我的 arduino 以获取 IR 信号并在串行中打印值时,即使我告诉串行以十六进制形式打印,它也会打印为4E5CE275On
,所以它应该是 0x1 . 我想也许我只是不明白它是如何工作的,所以我尝试发送 0 并得到相同的结果。 我不知道出了什么问题。 这是我的代码:
#include <FastLED.h>
#include <IRremote.h>
#define NUM_LEDS 150
#define DATA_PIN 5
#define CLOCK_PIN 13
int IRpin = 7;
IRrecv irrecv(IRpin);
decode_results results;
CRGB leds[NUM_LEDS];
boolean LEDon = false;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
Serial.println("resetting");
LEDS.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
LEDS.setBrightness(84);
}
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
void loop() {
if (irrecv.decode(&results))
{
while((LEDon) == false)
{
Serial.print(results.value, HEX);
Serial.print("On");
static uint8_t hue = 0;
Serial.print("x");
// First slide the led in one direction
for(int i = 0; i < NUM_LEDS; i++) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
Serial.print("x");
// Now go in the other direction.
for(int i = (NUM_LEDS)-1; i >= 0; i--) {
// Set the i'th led to red
leds[i] = CHSV(hue++, 255, 255);
// Show the leds
FastLED.show();
// now that we've shown the leds, reset the i'th led to black
// leds[i] = CRGB::Black;
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
}
}
}
代码正在读取信号,如果存在信号,则 LED 开始运行,但稍后我想使用while(results.value) == 0)
LED 运行。
你有没有尝试过:
接收问题
如果接收不起作用,首先确保 Arduino 至少正在接收原始代码。 > Arduino 引脚 13 上的 LED 将在接收到 IR 时闪烁。 如果不是,那么可能是硬件问题。如果收到代码但无法解码,请确保代码在受支持的协议之一中。 如果代码应该被解码,但没有被解码,则某些测量时间可能不在预期时间的 20% 容差范围内。 您可以打印出最小和最大预期值并与原始测量值进行比较。
示例/IRrecvDump 草图将转储接收到的数据的详细信息。 dump 方法转储出这些持续时间,但将它们转换为微秒,并使用在空间测量前加上减号的约定。 这使得更容易保持标记和空间测量的直线。
IR 传感器通常会导致测量的标记比预期的要长,而空间比预期的要短。 代码将标记扩展 100us 以解决此问题(值 MARK_EXCESS)。 在这种情况下,您可能需要调整预期值或公差。
该库不支持同时发送和接收代码; 发送将禁用接收。
来自: http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html
PS我更愿意对此发表评论并询问,但遗憾的是我是新手,我的声誉仍然需要一些工作:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.