ratkins / rgbconverter Goto Github PK
View Code? Open in Web Editor NEWAn Arduino library for converting between HSL, HSV and RGB colour spaces.
License: Do What The F*ck You Want To Public License
An Arduino library for converting between HSL, HSV and RGB colour spaces.
License: Do What The F*ck You Want To Public License
did not want to clone the whole repo just for this.
diff --git a/RGBConverter.h b/RGBConverter.h
index 1a3c960..da92c41 100644
--- a/RGBConverter.h
+++ b/RGBConverter.h
@@ -12,7 +12,11 @@
#ifndef RGBConverter_h
#define RGBConverter_h
-#include "WProgram.h"
+#if (ARDUINO < 100)
+#include <WProgram.h>
+#else
+#include <Arduino.h>
+#endif
class RGBConverter {
I want to use your code in my future project, but you haven't given any license. Could you add it please?
I'm trying to use this library but I can't work out commands for it. Can some plz build an example for me that's HSV to RGB
many thanks
Hi! I have slightly modified your library to match existing data structure I used for led lighting.
So that I had int[3]
as rgb value instead of byte[3]
, inside a struct. I'm not so expert in C programming but seems that this change messed up the division between double and int and hslToRgb
gives me only or 255-255-255 or 0-0-0.
I have casted all number in double (adding a .0
after each number) and avoided to use 1 as hue/saturation/light value but 0.99 and everything works ok.
Like this snippet of code:
void hslToRgb(double h, double s, double l, double rgb[]) {
double r, g, b;
if (s == 0) {
r = g = b = l; // achromatic
} else {
double q = l < 0.5 ? l * (1.0 + s) : l + s - l * s;
double p = 2 * l - q;
r = hue2rgb(p, q, h + 1.0 / 3.0);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1.0 / 3.0);
}
rgb[0] = r * 255;
rgb[1] = g * 255;
rgb[2] = b * 255;
}
double hue2rgb(double p, double q, double t) {
if (t < 0) t += 1;
if (t > 1.0) t -= 1;
if (t < 1.0 / 6.0) return p + (q - p) * 6.0 * t;
if (t < 1.0 / 2.0) return q;
if (t < 2.0 / 3.0) return p + (q - p) * (2.0 / 3.0 - t) * 6.0;
return p;
}
Now it works like a charm, thanks!
Hi, I needed an HSL to RGB converter and was really excited to find this. However, when I started to use your library in my arduino project I kept getting grey values, as if my saturation was zero. After some digging I realized the cause of the issue was in the hue2rgb function in the cpp file - it would always fail the if statements with fractions and return p. This is because the integer division was rounding to zero. If you change the fractions from 1/2 to 1/2.0 this problem goes away and the converter works as it should!
Hi!
I've recently forked your project and decided to detach it from its Arduino dependency. We can still have the Arduino part as something extra but how about making the library more portable? I'm currently using it for a project that involves some ROS actions and LEDs where it is really handy. I also have a Raspberry Pi which I will soon attach to an LED stripe to play with it. The Arduino header (and types used in your version) pose the problem of using the library out of the box on non-Arduino platforms. Can you please view the changes I have made on my fork and maybe we can merge them with your project (if support for Arduino is to remain I can simply wrap my version of the library so that it can also use Arduino's data types)? I'm also considering (and even started) adding some testing for the library to check its behaviour.
Hello,
For each function that I try to call, it returns e.g. "hslToRgb was not declared in this scope".
However the library seems to be easy enough, I can't find a way to make it work.
Can you provide some instruction, please?
Thank you
Hi I'm.trying to use your library and it tops out at 170,170,170
Just wondering if you'd take a look
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.