Saturday 31 October 2020

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.



from Infrared not returning 1 as correct value

No comments:

Post a Comment