Need help sending custom values

  • So I'm building a sleep light for my son using Arduinos and Neopixels for the lgihting. I'm also attaching a radio to it so I can adjust the start/end time remotely and figured while I'm at it I'd like to be able to change the color of the lights both for the sleep mode and just to control the light remotely (If I can do it why shouldn't I ;-)).

    So I've figured out how to use V_VAR1-3 to send the light color and then V_LIGHT to turn it on/off manually.

    Now the problem is I want to be able to set the color for when manually controlling separate from when doing sleep mode. However I've run out of preset up custom vars. So I'm wondering if you can have multiple of the same "sensor" per node. Right now I had been using S_ARDUINO_NODE as my "Sensor" to receive messages from the gateway. This is my updated (untested since I'm at work) code. It looks like there are V_VAR4 and V_VAR5 and I'll most likely leverage those to handle the time variables coming from the gateway.

    I still need to add in the functions to check the time (and get updated time from the gateway/controller but my controller is in the mail (I'm sure I'll have more questions once I get that))

    So on to my questions.

    Is there a better way to send RGB values? What is the best way to send time values (ie 6:00, 19:30)?

  • Admin


    Send it as hex string in one VAR_x

    E.g. FFcc22

  • Contest Winner

    @hek said:


    Send it as hex string in one VAR_x

    E.g. FFcc22

    If you can pass them into MySensors as @hek suggested, you can decode them like this:

    typedef struct {
      byte red;
      byte green;
      byte blue;
    RGB decode(unsigned long value);  // fixed this!!
    char * myCstring = "FF00FF";  //<< you recieved this via mySensors radio!!!  (RRGGBB)
    void setup()
      unsigned long myLong = strtol(myCstring,NULL,16); //<< the magic is here in the strtol() function!!!
      Serial.println(myLong, BIN);
      RGB newLedColor = decode(myLong);
      char buffer[30] = "\0";
      sprintf(buffer, "Red = %03d, Green = %03d, Blue = %03d",,,;//<<< you want these to set your leds!!!
    void loop()
    RGB decode(unsigned long value)
      RGB color; = lowByte(value); = lowByte(value >> 8); = lowByte(value >> 16);
      return color;

  • @BulldogLowell Thanks that sounds much easier than what I had been planning on doing.

    I'll give this a try tonight.

  • Contest Winner


    good, let us know if you need any assistance... Note I noticed that I had an error in the code above and I updated it for you. Sorry 'bout that.

Log in to reply

Suggested Topics

  • 1
  • 15
  • 10
  • 97
  • 53
  • 4
  • 1
  • 7