I have a led strip and an IR receiver connected.
When adding led strip controls, the IR reading does not work. -> "Decoded Unknown(0): Value:0 Adrs:0 (0 bits)"
Just commenting out "valot()" in main loop makes the IR work again. -> Decoded NEC(1): Value:FFA25D Adrs:0 (32 bits)
16753245
CH-
The led strip alone can be properly controlled by Arduino (by altering the variables by hand, randomly, incrementally, etc).
Can you help?
#include "IRLibAll.h"
#define CHnappi 16736925
#define CHplus 16769565
#define CHminus 16753245
//Create a receiver object to listen on pin 2
IRrecvPCI myReceiver(2);
//Create a decoder object
IRdecode myDecoder;
// Define the number of LEDs
#define NUM_LEDS 20
// Define SPI Pin
#define PIN A1
// Baudrate, higher rate allows faster refresh rate and more LEDs (defined in /etc/boblight.conf)
#define serialRate 115200
//// End of user definitions /////
// Utilises FastSPI_LED2
#define FORCE_SOFTWARE_SPI
#define FORCE_SOFTWARE_PINS
#include <FastSPI_LED2.h>
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Adalight sends a "Magic Word" (defined in /etc/boblight.conf) before sending the pixel data
uint8_t prefix[] = {'A', 'd', 'a'}, hi, lo, chk, i;
// initialise LED-array
CRGB leds[NUM_LEDS];
int B = 1;
int h = 255;
int s = 30;
int v = 200;
int hue = 55;
int sat = 30;
int val = 20;
int pun, vih, sini;
int r, g, b;
unsigned long prev;
void setup()
{
Serial.begin(9600);
myReceiver.enableIRIn(); // Start the receiver
Serial.println(F("Ready to receive IR signals"));
pinMode(A0, INPUT_PULLUP);
FastLED.addLeds<WS2812, PIN, RGB>(leds, NUM_LEDS);
}
void loop() {
if (millis() > prev + 100 && digitalRead(A0) == LOW) {
prev = millis();
off();
}
kauko();
// HSV_to_RGB(hue, sat, val);
Serial.println(r);
Serial.println(g);
Serial.println(b);
Serial.println();
Serial.println(hue);
Serial.println(sat);
Serial.println(val);
Serial.println();
Serial.println();
valot();
// delay(2000);
}
void kauko() {
if (myReceiver.getResults()) {
myDecoder.decode(); //Decode it
myDecoder.dumpResults(false); //Now print results. Use false for less detail
Serial.println(myDecoder.value);
switch (myDecoder.value) {
case CHnappi:
hue = hue + 20;
if (hue >= 360)hue = 0;
Serial.println("CH");
break;
case CHplus:
val += 10;
if(val>=100)val=100;
Serial.println("CH+");
break;
case CHminus:
val -= 10;
if(val<=0)val=0;
Serial.println("CH-");
break;
}
myReceiver.enableIRIn(); //Restart receiver
}
}
void off() {
B = !B;
}
void valot()
{
for (int i = 0; i < NUM_LEDS; i++) {
// strip.setPixelColor(i, strip.Color(pun * B, vih * B, sini * B));
strip.setPixelColor(i, strip.Color(r * B, g * B, b * B));
strip.show(); // This sends the updated pixel color to the hardware.
}
// delay(100);
}
void HSV_to_RGB(float h, float s, float v)
{
int i;
float f, p, q, t;
h = max(0.0, min(360.0, h));
s = max(0.0, min(100.0, s));
v = max(0.0, min(100.0, v));
s /= 100;
v /= 100;
if (s == 0) {
// Achromatic (grey)
r = g = b = round(v * 255);
return;
}
h /= 60; // sector 0 to 5
i = floor(h);
f = h - i; // factorial part of h
p = v * (1 - s);
q = v * (1 - s * f);
t = v * (1 - s * (1 - f));
switch (i) {
case 0:
r = round(255 * v);
g = round(255 * t);
b = round(255 * p);
break;
case 1:
r = round(255 * q);
g = round(255 * v);
b = round(255 * p);
break;
case 2:
r = round(255 * p);
g = round(255 * v);
b = round(255 * t);
break;
case 3:
r = round(255 * p);
g = round(255 * q);
b = round(255 * v);
break;
case 4:
r = round(255 * t);
g = round(255 * p);
b = round(255 * v);
break;
default: // case 5:
r = round(255 * v);
g = round(255 * p);
b = round(255 * q);
}
}