These are chat archives for Makuna/NeoPixelBus

14th
Nov 2016
Michael Miller
@Makuna
Nov 14 2016 08:33
glad to hear it. Just a few comments...
The strip.SetPixelColor can directly take any of the color objects
The got_int isn't really needed above; just replace it in hue value like got_float / 360.0f,
protolyser
@protolyser
Nov 14 2016 08:56

thanks for your help. thats how I have it now using the hslCustom and COLOR thing solves the brightness setting for me right now:

// Setup Standard Dynamic Custom Color Values
float saturationValue = 1.0f;
float lightnessValue = 0.004f;
float hueValue = 360;

// Setup Custom Color
HslColor hslCustom(hueValue/360.0f, saturationValue, lightnessValue); 

// Setup COLOR Transporter Variable + Standard Color
HslColor COLOR = hslCustom;

// Byte* --> Float
float char_to_float (byte* payload, unsigned int length) {       
    // PAYLOAD --> FLOAT/INT
      for (i = 0; i<length; i++) {
      message_buff[i] = payload[i];
      }
      message_buff[i] = '\0';
      const char *p_payload = message_buff;

      got_float = atof(p_payload);

      return got_float;
}

String payloader; // MQTT Payload --> String Helper
String topicer; // MQTT Payload --> String Helper

// ----------------------------------------------------------------------------------------------
// GENERAL MQTT CALLBACK
// ----------------------------------------------------------------------------------------------
void callback(char* topic, byte* payload, unsigned int length) {

  //Make topic and payload --> String
  payload[length] = '\0';
  payloader = String((char*)payload);
  topicer = String(topic);

  if (payloader == "Restart") {
    ESP.restart();
  }

  // COLOR SETTINGS
  if (topicer == "ledmatrix/color"){
      // CONVERT byte* payload --> float
      hueValue = char_to_float (payload, length);
      // GENERATE NEW CUSTOM COLOR
      HslColor hslCustom(hueValue/360.0f, saturationValue, lightnessValue); 
      // SET NEW CUSTOM COLOR
      COLOR = hslCustom;
  }
  // BRIGHTNESS SETTINGS
  if (topicer == "ledmatrix/lightness"){
      // CONVERT byte* payload --> float
      lightnessValue = char_to_float (payload, length);
      // GENERATE NEW CUSTOM COLOR
      HslColor hslCustom(hueValue/360.0f, saturationValue, lightnessValue); 
      // SET NEW CUSTOM COLOR
      COLOR = hslCustom;
  }
}

// DISPLAY STUFF
void line(){
    for(x=106; x<=109; x++) {
    strip.SetPixelColor(x, COLOR);
    }
}

// Different Modes in Loop
[....]
     case 8:
       turnOff(); 
        strip.SetPixelColor(topo.Map(left, top), COLOR);
        strip.SetPixelColor(topo.Map(right, top), COLOR);
        strip.SetPixelColor(topo.Map(right, bottom), COLOR);
        strip.SetPixelColor(topo.Map(left, bottom), COLOR);
        strip.SetPixelColor(topo.Map(centerx, centery), COLOR);
        strip.Show();
      break;

That works for me right now to be able to set the brightness and color via MQTT. If you have suggestions on how to make it better I'm always open for it :)

Michael Miller
@Makuna
Nov 14 2016 19:41

Looks good.
A preference I have is to minimize the places for strip.Show(). So loop tends to look like....

void loop() {
    serviceWiFiStuff()
    animations.UpdateAnimations();
    applyStaticColors();
   strip.Show();
}

the strip.Show() is smart in that it will only do work if there were changes.
The reason behind this is calling show can take time to prepare and send the data. And if you accidentally call it more than once (with small change between them) in the same loop pass; it will take twice as long. But if you are careful it doesn't matter.

protolyser
@protolyser
Nov 14 2016 19:58
ok thanks, makes sense