I want to make a controller for 2 WS21812B Strips with a Arduino Nano. I want to send data to the Arduino with the Computer or my phone to change colors or effects, but the arduino doesn't receive any data. Only if I comment out the effects the arduino receive messages.
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
#include "FastLED.h"
byte NUM_LEDS[2] = {50, 53};
#define LED_DATA_PIN 3
#define BRIGHTNESS 255
CRGB leds[2][53];
// Filler animation attributes
CRGBPalette16 currentPalette = RainbowColors_p;
TBlendType currentBlending = LINEARBLEND;
uint8_t startIndex = 0;
int rt = 0, gr = 0, bl = 0, le = 3, de = 15, rt1 = 0, gr1 = 0, bl1 = 0, le1 = 3, de1 = 15;
byte mode = 0, mode1 = 0;
void setup()
{
Serial.begin(9600);
FastLED.addLeds<WS2812B, LED_DATA_PIN, GRB>(leds[0], NUM_LEDS[0]);
FastLED.addLeds<WS2812B, 6, GRB>(leds[1], NUM_LEDS[1]);
FastLED.setBrightness(BRIGHTNESS);
pinMode(5, OUTPUT);
analogWrite(5, 255);
mySwitch.enableReceive(0); // Empfänger ist an Interrupt-Pin "0" - Das ist am UNO der Pin2
FastLED.clear(true);
}
void loop() {
empf();
fade(0);
/*if(mode == 11){
analogWrite(5,0);
}else if(mode == 0){*/
/*}else if(mode == 1){
fillpallet(0);
}else if(mode == 2){
cylon(rt,gr,bl,le,de,0);
}else if(mode == 10){
ledsoff(0);
}*/
}
void cylon(int red, int green, int blue, int leng, int del, int strip) {
static int stri;
static bool set;
static int for1;
static int fb;
if (set && stri != strip) {
for1 = 0;
stri = strip;
fb = 0;
}
if (set == false) {
stri = strip;
set = true;
}
unsigned long t = del;
static unsigned long _ETimer;
if ( millis() - _ETimer >= (t)) {
_ETimer += (t);
if (for1 == NUM_LEDS[strip]) {
for1--;
fb = 1;
} else if (for1 == 0) {
fb = 0;
}
if (fb == 1) {
for1--;
} else {
for1++;
}
}
for (int l = 0; l < leng; l++) {
if (for1 + l <= NUM_LEDS[strip]) {
leds[strip][for1 + l] = CRGB(red, green, blue);
}
}
FastLED.show();
for (int l = 0; l < leng; l++) {
if (for1 + l <= NUM_LEDS[strip]) {
leds[strip][for1 + l] = CRGB(0, 0, 0);
}
}
}
void ledson(int red, int green, int blue, int strip) {
for (byte i = 0; i < NUM_LEDS[strip]; i++) {
leds[strip][i] = CRGB(red, green, blue);
}
FastLED.show();
}
void ledsoff(byte strip) {
for (byte i = 0; i < NUM_LEDS[strip]; i++) {
leds[strip][i] = CRGB(0, 0, 0);
}
FastLED.show();
}
int r = 255;
int g = 0;
int b = 0;
void fade(int zahl) {
unsigned long t = 20;
static unsigned long _ETimer;
if ( millis() - _ETimer >= (t)) {
_ETimer += (t);
for (int i = 0; i < NUM_LEDS[zahl]; i++) {
leds[zahl][i] = CRGB(r, g, b);
}
FastLED.show();
if (r > 0 && b == 0) {
r--;
g++;
}
if (g > 0 && r == 0) {
g--;
b++;
}
if (b > 0 && g == 0) {
r++;
b--;
}
}
}
void fillpallet(int zahl) {
unsigned long t = 15;
static unsigned long _ETimer;
if ( millis() - _ETimer >= (t)) {
_ETimer += (t);
startIndex++; // speed
uint8_t colorIndex = startIndex;
for ( int i = 0; i < NUM_LEDS[zahl]; i++) {
leds[zahl][i] = ColorFromPalette(currentPalette, colorIndex, BRIGHTNESS, currentBlending);
colorIndex += 3;
}
FastLED.show();
}
}
void empf() {
if (mySwitch.available()) // Wenn ein Code Empfangen wird...
{
Serial.println("ab");
int value = mySwitch.getReceivedValue(); // Empfangene Daten werden unter der Variable "value" gespeichert.
//Serial.println(value);
if (value == 0) // Wenn die Empfangenen Daten "0" sind, wird "Unbekannter Code" angezeigt.
{
Serial.println("Unbekannter Code");
}
else // Wenn der Empfangene Code brauchbar ist, wird er hier an den Serial Monitor gesendet.
{
if (value > 99 && value < 140) {
String s = String(value);
char c[3];
s.toCharArray(c, 4);
Serial.println("test");
if (c[1] == '1') {
if (c[2] == '0') {
mode = 10;
} else if (c[2] == '1') {
mode = 0;
} else if (c[2] == '2') {
mode = 1;
} else if (c[2] == '3') {
mode = 2;
}
} else if (c[1] == '2') {
if (c[2] == '0') {
mode1 = 10;
} else if (c[2] == '1') {
mode1 = 0;
} else if (c[2] == '2') {
mode1 = 1;
} else if (c[2] == '3') {
mode1 = 2;
}
} else if (c[1] == '3') {
if (c[2] == '0') {
mode = 11;
} else if (c[2] == '1') {
mode = 0;
mode1 = 0;
} else if (c[2] == '2') {
mode = 1;
mode1 = 1;
} else if (c[2] == '3') {
mode = 1;
mode1 = 1;
}
}
}
if (value > 99999 && value < 130000) {
String s = "" + value;
char c[6];
s.toCharArray(c, 6);
if (c[1] == '1') {
if (c[2] == '1') {
rt = c[3] + c[4] + c[5] + 0;
} else if (c[2] == '2') {
gr = c[3] + c[4] + c[5] + 0;
} else if (c[2] == '3') {
bl = c[3] + c[4] + c[5] + 0;
} else if (c[2] == '4') {
de = c[3] + c[4] + c[5] + 0;
} else if (c[2] == '5') {
le = c[3] + c[4] + c[5] + 0;
}
} else if (c[1] == '2') {
if (c[2] == '1') {
rt1 = c[3] + c[4] + c[5] + 0;
} else if (c[2] == '2') {
gr1 = c[3] + c[4] + c[5] + 0;
} else if (c[2] == '3') {
bl1 = c[3] + c[4] + c[5] + 0;
} else if (c[2] == '4') {
de1 = c[3] + c[4] + c[5] + 0;
} else if (c[2] == '5') {
le1 = c[3] + c[4] + c[5] + 0;
}
}
}
}
mySwitch.resetAvailable(); // Hier wird der Empfänger "resettet"
}
}