javascriptc++arduinoinfrared

Infrared not returning 1 as correct value


I am trying to create a glove that when you turn your wrist down it sends 1 as an IR signal and if you turn your wrist up it returns a 0 for the glove I used 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)
})

I don't believe there is a problem there but when I go to my arduino to pick up the IR signal and print the value in the Serial it prints as 4E5CE275On even though I told the Serial to print in Hex form so it should be 0x1. I thought maybe I just don't understand how that works so I tried sending 0 and I got the same result. I do not know what is going wrong. here is my code:

#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);
          }
         
  }
    }
}

The code is reading for a signal and if signal is present the leds start running but later on I want to use while(results.value) == 0) the LEDS run.


Solution

  • Have you tried:

    Problems with Receiving
    If receiving isn't working, first make sure the Arduino is at least receiving raw codes. > The LED on pin 13 of the Arduino will blink when IR is being received. If not, then there's probably a hardware issue.

    If the codes are getting received but cannot be decoded, make sure the codes are in one of the supported protocols. If codes should be getting decoded, but are not, some of the measured times are probably not within the 20% tolerance of the expected times. You can print out the minimum and maximum expected values and compare with the raw measured values.

    The examples/IRrecvDump sketch will dump out details of the received data. The dump method dumps out these durations but converts them to microseconds, and uses the convention of prefixing a space measurement with a minus sign. This makes it easier to keep the mark and space measurements straight.

    IR sensors typically cause the mark to be measured as longer than expected and the space to be shorter than expected. The code extends marks by 100us to account for this (the value MARK_EXCESS). You may need to tweak the expected values or tolerances in this case.

    The library does not support simultaneous sending and receiving of codes; transmitting will disable receiving.

    from: http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html

    P.S. I would have preferred to comment this and ask, but sadly I am new and my reputation still needs some work :)