Hi all.
I´m trying to make a ws2812b strip connected to a NodeMcu, and that part works.
Next I want to change color from a UDP input.
I get the message on UDP, and that is in this format : 200,200,200
Is there a way to convert it, så the neopixel can use it ?
regards
Kim
It sounds plausible, you'll need to parse the three numbers from the packet and apply them to one or more LEDs.
Can you post the code that gets the message over UDP?
Example #5 of the serial input basics tutorial, (updated) shows how to use the strtok function to parse values from a string.
I like to use strtoul for unsigned integer scanning.
char data[] = "200,201,202";
uint8_t rValue, gValue, bValue;
void setup() {
char* behind;
Serial.begin(115200);
Serial.print(F("data to scan \""));
Serial.print(data);
Serial.println(F("\""));
rValue = strtoul(data, &behind, 0); // allows for hex in 0x.. notation
if (behind != nullptr && *behind == ',') {
behind++;
}
gValue = strtoul(behind, &behind, 0);
if (behind != nullptr && *behind == ',') {
behind++;
}
bValue = strtoul(behind, &behind, 0);
Serial.print(F("parsed values are "));
Serial.print(rValue);
Serial.write(',');
Serial.print(gValue);
Serial.write(',');
Serial.println(bValue);
}
void loop() {}
Output:
data to scan "200,201,202"
parsed values are 200,201,202
You could drop the checks
if (behind != nullptr && *behind == ',') {
if you are absolutely sure about the input format.
system
Closed
April 12, 2022, 11:52am
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.