Comments (7)
Regarding the JLedSequence
, I think you hit the same problem as described in #90:
The JLedSequence sequence object has a state and in your setup, the sequence is in state "not running", because both JLed objects are already/initially Off. So further calls to sequence.Update() will have no effect. Try to call sequence.Reset() in your ProcessLine function.
In your case also once the sequence "is done", it will not re-start when you reset the contained LEDs. The JLedSequence
object itself has to be resetted using Reset()
from jled.
How often is the laser_fade_in_slow
function called?
from jled.
On demand, i.e. triggered remotely, but never anywhere close to intervals shorter than FADESLOW
, which is 3000ms. Basically the idea is to turn the "laser" on with a fade in but leave it on after that until another function makes it turn off.
from jled.
I think you need to change to something like:
#include <jled.h>
#define LASER_PIN 21
#define FRONTLIGHT_PIN 22
#define FADESLOW 3000
JLed pwm_pins[] = {JLed(LASER_PIN).Breathe(255).Forever(), JLed(FRONTLIGHT_PIN).Off()};
void setup() {
Serial.begin(9600);
}
void laser_fade_in_slow(int brightness) {
if (brightness){
Serial.print("Set to FadeOn with brightness=");
Serial.println(brightness);
pwm_pins[0].FadeOn(FADESLOW).MaxBrightness(brightness).Repeat(1).Reset();
} else {
Serial.println("Set to FadeOff");
pwm_pins[0].FadeOff(FADESLOW).Repeat(1).Reset();
}
}
void loop() {
static unsigned long last_change_time_ = 0;
pwm_pins[0].Update();
pwm_pins[1].Update();
delay(1);
// simulation: every 5s call laser_fade_in_slow with a new random brightness
if (millis() - last_change_time_ > 5000) {
last_change_time_ = millis();
const auto brightness= random(0, 255);
if (brightness < 100) {
laser_fade_in_slow(0);
} else {
laser_fade_in_slow(brightness);
}
}
}
Otherwise, the effect for pwn_pins[0] will run Forever
, because it was initially set to do so.
Also when using the JLedSequence
, once it is finished, changes to the contained Leds in pwm_pins
will have no effect, since the JLedSequence is configured to just run once.
from jled.
Okay... so say I do this for both pins:
#include <jled.h>
#define LASER_PIN 21
#define FRONTLIGHT_PIN 22
#define FADESLOW 3000
JLed pwm_pins[] = {JLed(LASER_PIN).Breathe(255).Forever(), JLed(FRONTLIGHT_PIN).Off()};
void laser_fade_in_slow(int brightness, int what) {
if (brightness){
Serial.print("Set to FadeOn with brightness=");
Serial.println(brightness);
pwm_pins[what].FadeOn(FADESLOW).MaxBrightness(brightness).Repeat(1).Reset();
} else {
Serial.println("Set to FadeOff");
pwm_pins[what].FadeOff(FADESLOW).Repeat(1).Reset();
}
}
Note that pwm_pins[0]
starts with a Breathe(255).Forever()
, while the other one doesn't.
Then, when I call laser_fade_in_slow(255, 1)
, it works perfectly (I can later on update with no issue), but with laser_fade_in_slow(255, 0)
it makes the FadeOn on LASER_PIN
, but afterwards I can't update it.
from jled.
I modified the example to call your laser_fade_in_slow
function every 5s with random values. Works as expected, LEDs changing state continously (I am using an ESP32 for the test). Could you pleas try the example and the latest JLed Version? Which Micro controller and Framework are you using?
#include <jled.h>
#define LASER_PIN 21
#define FRONTLIGHT_PIN 22
#define FADESLOW 3000
#define LASER_PIN 21
#define FRONTLIGHT_PIN 22
#define FADESLOW 3000
JLed pwm_pins[] = {JLed(LASER_PIN).Breathe(255).Forever(),
JLed(FRONTLIGHT_PIN).Off()};
void laser_fade_in_slow(int brightness, int what) {
Serial.print("For LED=");
Serial.print(what);
if (brightness) {
Serial.print(", set to FadeOn with brightness=");
Serial.println(brightness);
pwm_pins[what]
.FadeOn(FADESLOW)
.MaxBrightness(brightness)
.Repeat(1)
.Reset();
} else {
Serial.println(", set to FadeOff");
pwm_pins[what].FadeOff(FADESLOW).Repeat(1).Reset();
}
}
void setup() {
Serial.begin(9600);
}
void loop() {
static unsigned long last_change_time_ = 0;
pwm_pins[0].Update();
pwm_pins[1].Update();
delay(1);
// every 5s call laser_fade_in_slow with a new random brightness
if (millis() - last_change_time_ > 5000) {
last_change_time_ = millis();
const auto brightness = random(0, 255);
const auto what = random(0, 2);
if (brightness < 100) {
laser_fade_in_slow(0, what);
} else {
laser_fade_in_slow(brightness, what);
}
}
}
from jled.
Hi!
Sorry for not answering for a while. I didn't have the time to test this part until now.
TL;DR
- your test code works perfectly, no issue
- the framework I am using is Arduino, board is a RF69HCW featherm0 board. I am also using
RadioHead
and neopixelbus for managing radio communications and controlling RGB ledstrips respectively. The code for the project I am making is here - Issue is now solved, process for it is below
Step 1. Adding Repeat(1)
to pwm_pins[X].FadeOn(FADESLOW).MaxBrightness(brightness);
makes the animation only be triggered once, which accomplishes the "stay on forever" part.
Step 2. Adding Reset()
to pwm_pins[X].FadeOn(FADESLOW).MaxBrightness(brightness).Repeat(1);
doesn't seem to solve the "unable to update sequence" afterwards (see below)
Step 3. I saw in your code that you perform pwm_pins[0].Update();
and pwm_pins[1].Update();
in the loop, instead of a sequence.Update();
of a JLedSequence sequence(JLedSequence::eMode::PARALLEL, pwm_pins);
that I had declared after the pwm pins (see first comment). This seems to solve the issue, and actually, seems like the JLedSequence
is no longer necessary and I don't fully understand why. Eitherway, issue seems to be solved and code is updated... so many thanks for your support, your code, and your library ❤️
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
- jled to control RGB? HOT 7
- 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.