Hello,
ich have configured an arduino nano via nrf24L01+ and a LED-Stripe. My Idea is to send a LEDNumber and a HEX-Code for the color to set the LED to Color xy...
I use FHEM and a own Perl-Method to convert the HEX Code to an Splittable string. This i send via Network-GW to my arduino as String.
At this moment where the code is sending other receivers like Temp-Sensors sending 12502°C as Temperatur...
I dont find the problem.
Can somebody help?
The sendet code via FHEM is:
set <NAME> status7 0-0-255
#include <MySensor.h>
#include <SPI.h>
#include <EEPROM.h>
#include <MyTransportNRF24.h>
#include <MyHwATMega328.h>
#include <RemoteReceiver.h>
#include <RemoteTransmitter.h>
#include <InterruptChain.h>
#include "FastLED.h"
#define DATA_PIN 3
#define CLOCK_PIN 13
#define NUM_LEDS 19
CRGB leds[NUM_LEDS];
#define NUMBER_OF_OUTLETS 99
#define SN "LEDRahmenEG"
#define SV "1.6"
const byte SC_CHILD_ID = 0 ;
//unsigned long receivedCode = 0 ;
MySensor gw;
MyMessage scene_on(SC_CHILD_ID, V_LEVEL);
MyMessage scene_off(SC_CHILD_ID, V_LEVEL);
void setup() {
Serial.begin(115200);
gw.begin(incomingMessage);
gw.sendSketchInfo(SN, SV);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
//TEST
//leds[9].g=1;
//leds[9].b=255;
//leds[10].r=255;
//leds[11].b=255;
//FastLED.show();
// Create a child device for each outlet
for (int sensor = 1; sensor <= NUMBER_OF_OUTLETS; sensor++) {
gw.present(sensor, S_LIGHT);
delay(2);
}
}
void loop() {
gw.process();
}
String getValue(String data, char separator, int index) {
int found = 0;
int strIndex[] = {0, -1};
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}
//command has been received from gateway
void incomingMessage(const MyMessage &message) {
Serial.println(message.sensor);
Serial.println(".......");
Serial.println(message.getInt());
if (message.type == V_LIGHT) {
Serial.print("LED ID #: ");
Serial.println(message.sensor);
Serial.print("Color: ");
Serial.println(message.getString());
//receive String like 125-255-111 call getValue and split
//.toInt() convert the String Number to int and would be assigned to the LED
leds[message.sensor].r = getValue(message.getString(), '-', 0).toInt();
leds[message.sensor].g = getValue(message.getString(), '-', 1).toInt();
leds[message.sensor].b = getValue(message.getString(), '-', 2).toInt();
FastLED.show();
if (message.sensor == 99) {
for (int i = 0; i < NUM_LEDS; ++i) {
leds[i].r = getValue(message.getString(), '-', 0).toInt();
leds[i].g = getValue(message.getString(), '-', 1).toInt();
leds[i].b = getValue(message.getString(), '-', 2).toInt();
FastLED.show();
}
}
}
delay(50);
}
The Serial-Monitor shows
- message.sensor = 7
- message.getString() = 0-0-255enEG
Why is there "enEG" at the end?
Thanks
Christian