Comments (7)
Yes, that should be possible. The simplest approach would be to fade in RGB colorspace, with something like (untested):
// fade from (0,0,0) to (255,97,3) in 1s and wait 5s afterwards
JLed leds[] = {
JLed(1).Fade(0, 255, 1000).DelayAfter(5000),
JLed(2).Fade(0, 97, 1000).DelayAfter(5000),
JLed(3).Fade(0, 3, 1000).DelayAfter(5000)
};
auto rgbLED = JLedSequence(JLedSequence::eMode::PARALLEL, leds);
void loop() {
static auto stage = 0;
if (!rgbLED.Update() && stage == 0) {
// fade to (65,105,255) after first configuration is reached
leds[0].Fade(255, 65, 1000);
leds[1].Fade(97, 105, 1000);
leds[2].Fade(3, 255, 1000);
rgbLED.Reset();
stage++;
}
}
The fade
method is pretty new, make sure to update JLed.
However I'm not sure if this looks as expected (i.e. fade from off/black to initial color) and if its not better to do color calculations in HSV or HSL space.
The Problem sounds interesting, I will do some research in the next days.
from jled.
The challenge with a smooth RGB cross fade is the steps from one colour value to another to time it so each of the three LEDs reach their end value at (roughly) the same time. The code above looks a bit abrupt to me:
#include <jled.h> // https://github.com/jandelgado/jled
// fade from (0,0,0) to (255,97,3) in 1s and wait 5s afterwards
JLed leds[] = {
JLed(9).Fade(0, 255, 1000).DelayAfter(5000),
JLed(10).Fade(0, 97, 1000).DelayAfter(5000),
JLed(11).Fade(0, 3, 1000).DelayAfter(5000)
};
auto rgbLED = JLedSequence(JLedSequence::eMode::PARALLEL, leds);
void setup()
{
}
void loop() {
static auto stage = 0;
if (!rgbLED.Update() && stage == 0) {
// fade to (65,105,255) after first configuration is reached
leds[0].Fade(255, 65, 1000);
leds[1].Fade(97, 105, 1000);
leds[2].Fade(3, 255, 1000);
rgbLED.Reset();
stage++;
}
}
I found this description of cross fading and the Arduino code looks good, but it uses blocking calls (DELAY) which is no good for my purposes as the final sketch will need to control other LEDs separate from this RGB:
* Imagine a crossfade that moves the red LED from 0-10,
* the green from 0-5, and the blue from 10 to 7, in
* ten steps.
* We'd want to count the 10 steps and increase or
* decrease color values in evenly stepped increments.
* Imagine a + indicates raising a value by 1, and a -
* equals lowering it. Our 10 step fade would look like:
*
* 1 2 3 4 5 6 7 8 9 10
* R + + + + + + + + + +
* G + + + + +
* B - - -
*
* The red rises from 0 to 10 in ten steps, the green from
* 0-5 in 5 steps, and the blue falls from 10 to 7 in three steps.
*
* In the real program, the color percentages are converted to
* 0-255 values, and there are 1020 steps (255*4).
*
* To figure out how big a step there should be between one up- or
* down-tick of one of the LED values, we call calculateStep(),
* which calculates the absolute gap between the start and end values,
* and then divides that gap by 1020 to determine the size of the step
* between adjustments in the value.
*/
I'm not sure your library can do this without a big feature change.
from jled.
I worked up a non-blocking cross-fade but it's not as smooth a fade as your library. Still gotta try out your code.
from jled.
Actually, your code looks pretty good. I added a DelayBefore() to each pin as ultimately there will be other things that need to occur before this sequence.
#include <jled.h> // https://github.com/jandelgado/jled
// fade from (0,0,0) to (255,97,3) in 1s and wait 5s afterwards
JLed leds[] = {
JLed(9).Fade(255-0, 255-255, 3000).DelayBefore(2000).DelayAfter(4000),
JLed(10).Fade(255-0, 255-97, 3000).DelayBefore(2000).DelayAfter(4000),
JLed(11).Fade(255-0, 255-3, 3000).DelayBefore(2000).DelayAfter(4000)
};
auto rgbLED = JLedSequence(JLedSequence::eMode::PARALLEL, leds);
void setup() {
}
void loop() {
static auto stage = 0;
if (!rgbLED.Update() && stage == 0) {
// fade to (65,105,255) after first configuration is reached
leds[0].Fade(255-255, 255-65, 1000);
leds[1].Fade(255-97, 255-105, 1000);
leds[2].Fade(255-3, 255-255, 1000);
rgbLED.Reset();
stage++;
}
}
I still need to think about overall brightness - not sure if MaxBrightness() will work when there are 3 separate LED elements all at different PWMs.
from jled.
Sounds great. In parallel I'm working on an example using a HAL for RGB LED's, but I'll need some time. Will keep you updated.
from jled.
This is my usage of crossfade and usage of this library
https://github.com/Welsyntoffie/csgo-gsi-python-to-arduino/tree/develop/arduino/CSGO_lighting_controller
from jled.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 5 days
from jled.
Related Issues (20)
- Multiple HALs HOT 7
- Change PWM base frequency HOT 4
- Question: How to pass to funtion HOT 2
- Minimum brightness HOT 8
- Blink twice HOT 2
- Evolution for non PWM pins HOT 2
- times in millis should be 32bit values HOT 3
- Make fade-resolution choosable HOT 5
- Why is 'MinBrightness' not in red font HOT 2
- CTRL_ANODE HOT 4
- JLedSequence.Stop() not working HOT 1
- Question/Feature: Get current brightness HOT 11
- How to control 15 gpio pins HOT 8
- Return pin's previous state after Blink is over HOT 2
- Repeat() and DelayAfter() on the same effect in a sequence HOT 4
- Is there a way to use a single JLED to control a bicolor led? HOT 2
- Simulate PWM for all pins to enable PWM for all pins without hardware PWM HOT 1
- Update() not returning false for On() HOT 4
- Delay only working for low values HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jled.