I’m a true newbie. Sorry if this question has an obvious answer to most of you. But...
I'm playing around with my Arduino and a 3-color LED. The simple sketch has you varying the BRIGHTNESS of each color between 0 and 255. So that’s basically 8-bit color, right? Except, wait! Does changing those values actually change the “color” (frequency) of the emitted light? Or, does it change the INTENSITY of that light but not the color? I got to thinking about this because I thought it would be an interesting exercise to automate showing all the possible colors (16 million is it?). But I don’t see anything like that. In fact, it looks like there are only 8 variants of colors (3 binary places).
am I off the beam here?
There are 3 leds inside of a multicolored led, red, green, and blue. What you are varying is the intensity of each led and then it is your eye that makes the color interpretation.
Pat Wicker (Portland, OR, USA)
Actually it is the brain that makes the colour interpretation. The brain uses data provided by the sensory data from three different types of retina cells in the eye. Colour is just how we experience the output of this computation. Colour only exists as a brain code, it does not exist "out there" in the physical world.
https://archive.nerdist.com/5-optical-illusions-that-show-you-why-your-brain-messes-with-the-dress/
In order for a AI to see the world as we do it would have to perform the same computations. As it stands now computers just code colour as a vector of three values.
I’m a true newbie. Sorry if this question has an obvious answer to most of you. But...
I'm playing around with my Arduino and a 3-color LED. The simple sketch has you varying the BRIGHTNESS of each color between 0 and 255. So that’s basically 8-bit color, right? Except, wait! Does changing those values actually change the “color” (frequency) of the emitted light? Or, does it change the INTENSITY of that light but not the color? I got to thinking about this because I thought it would be an interesting exercise to automate showing all the possible colors (16 million is it?). But I don’t see anything like that. In fact, it looks like there are only 8 variants of colors (3 binary places).
am I off the beam here?
Sounds interesting... Have you tried modifying your sketch by adding a simple:
For i=0 to 255
Output i to LED & delay a little
Next
That would only display 255 colors, etc. How would you do it for more colors? Sounds interesting... Maybe that's what you have already done?
Have Fun,
Joe Lyddon
www.woodworkstuff.net
You hook each colour's pin up to a different output and cycle through colours like this (I haven't tested it, I just wrote it off the top of my head):
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;
int redVal = 0;
int greenVal = 0;
int blueVal = 0;
int redStep = 1;
int greenStep = 3;
int blueStep = 5;
// set pinmode to OUTPUT in the setup() function
pinMode(redPin, OUTPUT); // etc
void loop() {
// output the 3 values to the 3 pins
analogWrite(redPin, redVal); // etc
// update the values
redPin += redStep;
if (redStep > 255) {
redStep -= 256;
} // same for the other colours.
delay(100);
Well, thanks all for your thoughts. In fact, I have tried a sketch that randomly selects a different value for each color, mostly because I couldn’t think of a way to vary all 3 values uniformly. My original thought was to try every possible value and combination thereof just to see what all the colors looked like. I wound up settling for 3 random selections for each loop. That was enough to set me off on this quest. Once I decided intensity, what is apparently varied by setting this value, is not the same as hue, shades of color, I just decided with 3 variables I can make only 8 colors and I wrote a sketch to do that. It’s not very satisfactory looking!
As for the neurological interpretation of color and all that, I’m going to argue a little here. First, I will agree that a typical computer screen with lots of pixels of varying “color” is interpreted by your eye, blended and smoothed, and so forth. But that’s MANY pixels grouped together by your eye. This is ONE LED! (OK, three actually) In essence, one pixel. In my little experiment above you can see each of the colors separately when all 3 were activated. I’m guessing you need some number of LEDs in a group for it to look like some mixed color like lavender or orange.
So I still have this question: What are you actually varying when you change these values? Aren’t you adding more current (or is it voltage?) as you raise the value from 0 to 255? I’m guessing the LED, because of its physical construction, can only give off one frequency of light, or “color” for each internal LED. If so you only get 8 colors, not 16M.
i don’t mean to be argumentative here. Really. And thank you all for your responses!
glenn
The analog output of the Arduino is turned on (5 volt)) and off (0 volt) at a high frequency called pulse width modulation. The longer the pulse in on the brighter the LED. If you wanted a continuous analog signal you would have to use a digital to analog converter (DAC). You can combine the output from three LEDS each giving off a different wavelength of light such as a red LED, a green LED and a blue LED to make a range of colors.
Each pixel is a different combination of two different LEDS which have been varied between 0 and 255.
@robotbuilder. Thanks...that helps me a lot. I’m going to play some more and get my understanding fixed.
This might let you have a little extra Fun with LEDs...
Have Fun,
Joe Lyddon
www.woodworkstuff.net
Try my code:
#include <avr/io.h>
#include <util/delay.h>
/**
Scetch ColorBlend_CommonCathode is a color fade/blend routine for a tri-color
common cathode led connected to Arduino Uno digital pins 9, 10, and 11 as PWM
outputs. Colors transition from blue through teal, green, yellow, orange, red,
violet, purple, and back to blue. With common cathode tri-colored leds,
analogWrite() value of 0 results in a full 'off' state, and analogWrite()
value of 255 results in a full 'on' state. This scetch works with common
anode tri-colored leds, only the color blend runs in the opposite order.
Written in Arduino C language.
@author Mike Tonge
@date 12/03/2019
*/
// Constants
const uint8_t DELAY_TIME = 100; // Delay time (miliseconds)
const uint8_t redLED = 9; // Red on digital pin 9
const uint8_t grnLED = 10; // Green on digital pin 10
const uint8_t bluLED = 11; // Blue on digital pin 11
const uint8_t OFF = 0; // Value used to turn led off
// Variables
uint8_t redVal = 0; // Red value
uint8_t grnVal = 0; // Green value
uint8_t bluVal = 0; // Blue value
void setup() {
pinMode(redLED, OUTPUT); // Set pin 9 as output
pinMode(grnLED, OUTPUT); // Set pin 10 as output
pinMode(bluLED, OUTPUT); // Set pin 11 as output
}
void loop() {
for (int count = 0; count <= 765; count++) {
switch (count) {
// Red is off, Green gets brighter, Blue gets dimmer
case 0 ... 255:
redVal = OFF;
grnVal = count;
bluVal = 255 - count;
break;
// Red gets brighter, Green gets dimmer, Blue is off
case 256 ... 510:
redVal = count - 255;
grnVal = 510 - count;
bluVal = OFF;
break;
// Red gets dimmer, Green is off, Blue gets brighter
case 511 ... 765:
redVal = 765 - count;
grnVal = OFF;
bluVal = count - 510;
break;
default:
break;
} // End switch
analogWrite(redLED, redVal);
analogWrite(grnLED, grnVal);
analogWrite(bluLED, bluVal);
delay(DELAY_TIME);
}
}
ZoolanderMicro, where small ideas are a big deal
#include #include /** Scetch ColorBlend_CommonCathode is a color fade/blend routine for a tri-color common cathode led connected to Arduino Uno digital pins 9, 10, and 11 as PWM outputs. Colors transition from blue through teal, green, yellow, orange, red, violet, purple, and back to blue. With common cathode tri-colored leds, analogWrite() value of 0 results in a full 'off' state, and analogWrite() value of 255 results in a full 'on' state. This scetch works with common anode tri-colored leds, only the color blend runs in the opposite order. Written in Arduino C language. @author Mike Tonge @date 12/03/2019 */ // Constants const uint8_t DELAY_TIME = 100; // Delay time (miliseconds) const uint8_t redLED = 9; // Red on digital pin 9 const uint8_t grnLED = 10; // Green on digital pin 10 const uint8_t bluLED = 11; // Blue on digital pin 11 const uint8_t OFF = 0; // Value used to turn led off // Variables uint8_t redVal = 0; // Red value uint8_t grnVal = 0; // Green value uint8_t bluVal = 0; // Blue value void setup() { pinMode(redLED, OUTPUT); // Set pin 9 as output pinMode(grnLED, OUTPUT); // Set pin 10 as output pinMode(bluLED, OUTPUT); // Set pin 11 as output } void loop() { for (int count = 0; count <= 765; count++) { switch (count) { // Red is off, Green gets brighter, Blue gets dimmer case 0 ... 255: redVal = OFF; grnVal = count; bluVal = 255 - count; break; // Red gets brighter, Green gets dimmer, Blue is off case 256 ... 510: redVal = count - 255; grnVal = 510 - count; bluVal = OFF; break; // Red gets dimmer, Green is off, Blue gets brighter case 511 ... 765: redVal = 765 - count; grnVal = OFF; bluVal = count - 510; break; default: break; } // End switch analogWrite(redLED, redVal); analogWrite(grnLED, grnVal); analogWrite(bluLED, bluVal); delay(DELAY_TIME); } }
ZoolanderMicro, where small ideas are a big deal
Have Fun,
Joe Lyddon
www.woodworkstuff.net