Go Down

Topic: Color variable (Read 802 times) previous topic - next topic

Zbyslaw

Is there a way to pass color variable from dashboard to arduino? I was looking around and can't seem to find an answer.

Thanks for any help!

pert

Are you asking about the "Color HSB" property? The HSB values you set using the color picker are available in your Arduino sketch via the variable name you configured when you added that property. If you have any questions about how to use that variable, let me know.

Zbyslaw

#2
Aug 26, 2019, 11:03 pm Last Edit: Aug 26, 2019, 11:20 pm by Zbyslaw
Thanks for help and sorry for late reply.

How can I for example set rgb led color to that from cloud? Can I get R,G and B values [edit:or individual H, S and B]? How to get them?

Thanks!

pert

#3
Aug 27, 2019, 05:42 am Last Edit: Aug 27, 2019, 12:42 pm by pert
Since I don't know which type of LED you're using and if you're using a library with it, I'll show you how to get both the HSB values and the RGB values and print them to the Arduino Web Editor's Monitor.

Create a thing.

Add a "Color HSB" property to the thing. The example code I am going to share assumes the variable name you chose is color. If you prefer a different variable name, you only need to adjust that part of the example code.

Click the "Edit Sketch" button.

Add the following code to the onColorpickerChange function:
Code: [Select]

  Serial.print("Hue = ");
  Serial.println(color.getValue().hue);
  Serial.print("Saturation = ");
  Serial.println(color.getValue().sat);
  Serial.print("Brightness = ");
  Serial.println(color.getValue().bri);
 
  // convert HSB to RGB
  // declare the variables to store the RGB values
  Color currentColor=Color(color.getValue().hue, color.getValue().sat, color.getValue().bri); // declare a variable of the Color data type and define it using the HSB values of the color variable
  byte RValue;
  byte GValue;
  byte BValue;
  currentColor.getRGB(RValue, GValue, BValue);  // the variables will contain the RGB values after the function returns
  Serial.print("R = ");
  Serial.println(RValue);
  Serial.print("G = ");
  Serial.println(GValue);
  Serial.print("B = ");
  Serial.println(BValue);


Click the "Secret" tab.

Fill in the SSID and password for your WiFi router.

Make sure your board is selected in the board menu at the top of the Arduino Web Editor window.

Click the upload button (rightward pointing arrow).

Wait for the upload to finish.

From the menu on the left side of the screen, click "Monitor".

Right click the "Go to IoT Cloud" button.

Click "Open link in new window".

Click the "Dashboard" tab.

You'll see a square color swatch labeled with the name you gave your "Color HSB" property.

Click twice on the square of color to show the color picker. Normally you only need to click the color swatch once to show/hide the color picker, but the first time you need to click it twice.

Use the mouse pointer to select your color from the color picker.

Click on the color swatch outside the picker area to change to the color you picked.

Switch to the browser window that has Arduino Web Editor open. You should see the HSB and RGB values of both the initial color and the new color you picked displayed in the Monitor window.

Zbyslaw


pert

You're welcome. I'm glad if I was able to be of assistance. Enjoy!
Per

Go Up