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.

    https://codebender.cc/sketch:90239

    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

    @Chaotic

    Send it as hex string in one VAR_x

    E.g. FFcc22


  • Contest Winner

    @hek said:

    @Chaotic

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

    @Chaotic

    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
  • 10
  • 198
  • 2
  • 2
  • 2

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts