jgillick / arduino-ledfader Goto Github PK
View Code? Open in Web Editor NEWAn arduino library to fade individual LEDs in the background without blocking your main program.
License: MIT License
An arduino library to fade individual LEDs in the background without blocking your main program.
License: MIT License
A great little library, thank you!
Can you make it also build for the fantastic ESP8266 platform?
Here is what I get when I try to compile for the Arduino core for ESP8266 WiFi chip:
On Arduino 1.6.11 and esp8266 board package, version 2.3.0:
In file included from /Users/foo/Arduino/libraries/LEDfader/Curve.cpp:8:0:
/Users/foo/Documents/Arduino/libraries/LEDfader/Curve.h:11:26:
fatal error: avr/pgmspace.h: No such file or directory
#include <avr/pgmspace.h>
^
compilation terminated.
exit status 1
Error compiling for board WeMos D1 R2 & mini.
When I just remove Curve.cpp
and Curve.h
, it all builds well. Perhaps related: Use function in "Curve::exponential" instead of table. Thank you!
I am trying to run this on an Atmega328P on a breadbord as stated here:
http://arduino.cc/en/Tutorial/ArduinoToBreadboard
(Minimal Circuit (Eliminating the External Clock), Number 5)
The "naked" µC thus runs at 8MHz (and is amazingly stable in it's frequency), but arduino-LEDFader seems to expect the µC to run at 20MHz. It would be great if the expected speed is openly defined somewhere. This would allow for the code to run at different speeds without affecting the quality of the Fade.
This is on Arduino 1.0.5, Mac OS X.
I get the above error, here's the full debug output if it helps:
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/variants/standard -I/Users/xxx/Documents/Arduino/libraries/LEDFader /var/folders/hq/9glncl0155v2t2745zzp6w3m0000gn/T/build3436876761086861667.tmp/singleLED.cpp -o /var/folders/hq/9glncl0155v2t2745zzp6w3m0000gn/T/build3436876761086861667.tmp/singleLED.cpp.o
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/variants/standard -I/Users/xxx/Documents/Arduino/libraries/LEDFader -I/Users/xxx/Documents/Arduino/libraries/LEDFader/utility /Users/xxx/Documents/Arduino/libraries/LEDFader/Curve.cpp -o /var/folders/hq/9glncl0155v2t2745zzp6w3m0000gn/T/build3436876761086861667.tmp/LEDFader/Curve.cpp.o
/Users/xxx/Documents/Arduino/libraries/LEDFader/Curve.cpp:11: warning: only initialized variables can be placed into program memory area
/Users/xxx/Documents/Arduino/libraries/LEDFader/Curve.cpp: In static member function 'static uint8_t Curve::exponential(uint8_t)':
/Users/xxx/Documents/Arduino/libraries/LEDFader/Curve.cpp:36: error: 'table' was not declared in this scope
Thanks in advance if you could help me out with this.
When the same value is called for instance in an infinite loop the fade function resets, i.e. by calling stop_fade()
and setting percent_done
to 0
.
Saving and verifying the Biodata-Sonification_26 sketch returns a "redefinition of void setup" error. I'm new to this, so sorry if this is the most obvious thing ever, but is there something in the code doing this?
Hello,
I'd like to use this library with ESP8266, but the resolution of PWM there is more than in most Atmegas (10 bits vs 8 bits), so.. I think I need to change all the '255' numbers in LEDFader.cpp and change all uint8_t
to uint16_t
, but what to do with Curve.cpp? The table is much more difficult to fix :). Should I use something like this?
Thank you for your amazing library, I love it!
Sorry for my English if it is bad.
Hello, i'm trying to make an elaborate lights show using the first example this but i'm facing some problems:
1.i can't get it to loop. simply copying the part from void setup to void loop does not seem to work.
2.There is only one fade in your example, from 0 to 255 in 3 seconds. Simply adding more fades after this does not work either. How can i add more of them?
3.Can i use 'for' statement to create fade pattterns and repeat them (or maybe even create a function of a pattern and insert it in different places?)
Thanks in advance!
First of all, thank you so much for this library! A fellow hobbyest pointed me to this code and with it I've been able to create the exact look I've been after for years, with only one small issue:
I want to fade up an LED in the void setup() loop over 2-3 seconds, but no matter how long I make the duration (it's set below to 7 seconds) it just sorta turns on - no real gradual fading. I'm using an Arduino Pro Mini board (5V, 16Mhz) and all 6 PWM pins.
Here's my code:
#include <LEDFader.h>
// Config for blinking coloured LEDs
// =================================
#define LED_NUM 5 // Number of LEDs
// 5 pin blinking LED setup
LEDFader leds[LED_NUM] = {
LEDFader(3), // PWM pin
LEDFader(5), // PWM pin
LEDFader(6), // PWM pin
LEDFader(9), // PWM pin
LEDFader(10), // PWM pin
};
// Config for pulsing amber LEDs
// =============================
#define AMBER_LED_PIN 11 // Amber LEDs (5 in pentagon shape)
#define FADE_UP_TIME 7000 // Time to power up
#define PULSE_TIME 750 // Fade down/up pulse time
#define MAX_BRIGHTNESS 225 // Max brightness of LEDs
#define MIN_BRIGHTNESS 125 // Min brightness of LEDs to fade to (pulse)
#define DIR_UP 1
#define DIR_DOWN -1
LEDFader amber_led;
int direction = DIR_UP;
void setup() {
randomSeed(analogRead(0));
amber_led = LEDFader(AMBER_LED_PIN);
amber_led.fade(MAX_BRIGHTNESS, FADE_UP_TIME);
}
void loop() {
// Pulsing amber LEDs
// ==================
amber_led.update();
// LED no longer fading, switch direction
if (!amber_led.is_fading()) {
// Fade down
if (direction == DIR_UP) {
amber_led.fade(MIN_BRIGHTNESS, PULSE_TIME);
direction = DIR_DOWN;
}
// Fade up
else {
amber_led.fade(MAX_BRIGHTNESS, PULSE_TIME);
direction = DIR_UP;
}
}
// Blinking coloured LEDs
// ======================
// try LEDFader's faster and slower methods:
// Increase the current fading speed by a number of milliseconds
// void faster(int by_seconds);
// Decrease the current fading speed by a number of milliseconds
// void slower(int by_seconds);
// Update all LEDs and start new fades if any are done
for (byte i = 0; i < LED_NUM; i++) {
LEDFader *led = &leds[i];
led->update();
// This LED is not fading, start a new fade
if (led->is_fading() == false) {
int duration = random(125, 500); // Duration between 100 to 750 ms (0.75 s)
// int duration = random(100, 750);
// int duration = random(0, 750);
// int duration = random(1000, 3000);
// Fade Up
if (led->get_value() == 0) {
byte intensity = random(75, 150); // Brightness intensity between 0 (off) to 255 (maximum)
// byte intensity = random(15, 50);
// byte intensity = random(0,75);
// byte intensity = random(100, 255);
led->fade(intensity, duration);
}
// Fade Down
else {
led->fade(0, duration);
}
}
}
}
Hi jgillick,
Thanks a lot for the great work you do! :-)
I have been using my arduinos, teensys, RGB SMD5050 LED strips and your library to create some nice light effects for my lab and have it working all nice and dandy, besides the functions that use the "percent" variable. I am now using some TI Launchpads with CCS and debugging the code. When I get to line 150 of LEDFader.cpp:
float percent = (float) time_diff / (float) duration;
Looking at the debug window i see:
"percent" variable: Type = "unknown", Value = "invalid register index 78
Hi, this script is really usefull but have a little problem.
I have a sketch when command with 4 I/O more than 6 led.fade command (start from 0 fade out and start from 255 fade in) in variuos time fade.
If in the schetck write more than 5 command to fade a led , this not working, Arduino ide 1.6.9 compile all without a errors but when I put HIGH pin can start VOID where I have command led.fade this not make nothing. I try to change a pinport after 5 command without succes, i try to make a another led command ex. LEDFader led = LEDFader(10); to LEDFader leds = LEDFader(10); without success...
I'm not an advanced programmer and i don't know how to resolve this problem for make a mod in library code.
Bye
When uploading the example "Multiple LEDs or RGB" I get the following error:
sketch_oct28a.ino: In function 'void loop()':
sketch_oct28a:32: error: request for member 'fade' in 'led', which is of non-class type 'LEDFader_'
sketch_oct28a:36: error: request for member 'fade' in 'led', which is of non-class type 'LEDFader_'
Hey
I wondered if this library could also fade an RGB. I've tried some things myself, but it does not work because a rgb uses 3 ports.
for the RGB i use following code:
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
//uncomment this line if using a Common Anode LED
#define COMMON_ANODE
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
setColor(255, 0, 0); // red
delay(1000);
setColor(0, 255, 0); // green
delay(1000);
setColor(0, 0, 255); // blue
delay(1000);
setColor(255, 255, 0); // yellow
delay(1000);
setColor(80, 0, 80); // purple
delay(1000);
setColor(0, 255, 255); // aqua
delay(1000);
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
thanks in advance!! 😄
ps: i really really like this libary!!!
Hi,
First to all thanks for these library,
I am a newbie and need some help here :)
I am using these and combining with timer library and it's works flawlessly.
I use these fader to PWM-ing the PIN which later used to control the voltage
I have a question in regards to read the value ()
my setup is
my archive is, I need to read the led value so the relay will state LOW (off) if only the led is completely off (0 value) because at a moment I got the relay off (LOW) at set time TOGETHER with led is STARTING to fade down (so I am loosing 10 second reflecting to the fade_time)
I am tried to use bellow code to implement (these was from your example code)
led.fade(0, FADE_TIME); // fade off led for 10 second
if (led.is_fading()== false) { // LED no longer fading
if (led.get_value() == 255 ) { // get led value ??? --
digitalWrite(relay, LOW); // turn off relay after led is completely off (0 value)
}}
I am was try to change the led.get_value to 0 and also changing the led.is_fading to true
but it doesn't work.
Do I make something wrong here ?
greatly appreciate with your help
I need to #include <avr/pgmspace.h>, but where can I get this library?
I'm trying to modify your example for randomly fading 6 LEDs to work with 11. If I just change the
#define LED_NUM 6
line to
#define LED_NUM 11,
and then add in the additional pins under the
LEDFader leds[LED_NUM] = {
section, it fades the 6 LEDs you originally chose, but the others will only flash on or off.
Am I missing something? I don't see anything in the rest of the code that would exclude the other pins from fading, but I'm not 100% sure what I'm doing yet.
Hello ,
I'm a bit of a newbie , and I need some help
I'm trying to make a lighthouse light.
I want to light up a led and fade it in one second and that 3 times in a row.
then I want a pause for 3 seconds and restart the 3 fading sequences .
I have managed it but without the fading.
Is there anything special about pin 0 in regards to your library? I can use this successfully on other pins, just not this one on the A-Star 328PB Micro. I looked through the code but couldn't see anything that would make it not work. I can use analogWrite() on this pin and other LED fading libraries, just not this one (which I love and have used extensively in my scale model work). I confirmed pin 0 doesn't work with the sindleLED example:
#include <LEDFader.h>
/*
Fades a single LED up and down using LED Fader.
Connect an LED to pin 3
*/
#define LED_PIN 0
#define FADE_TIME 2000
#define DIR_UP 1
#define DIR_DOWN -1
LEDFader led;
int direction = DIR_UP;
void setup() {
led = LEDFader(LED_PIN);
led.fade(255, FADE_TIME);
}
void loop() {
led.update();
// LED no longer fading, switch direction
if (!led.is_fading()) {
// Fade down
if (direction == DIR_UP) {
led.fade(0, FADE_TIME);
direction = DIR_DOWN;
}
// Fade up
else {
led.fade(255, FADE_TIME);
direction = DIR_UP;
}
}
}
EDIT: could it be this line from the header?
// Create a new LED Fader for a pin
LEDFader(uint8_t pwm_pin=0);
any plans on adding support ? ;)
really good btw !
thanks
Hello
thank a lot for this library, is very helpful.
I have only a question...I saw into the library that you define the interval (time of fading) like an unsigned int.
In this way the maximum time that I can set up it's about 65 second.
I need an interval like 1 hour... Is possible to change the interval from unsigned int to unsigned long?
Or you have choose this type of variable for a specific reason?
Thanks in advance.
Ivan
Hi Jgillick,
Could you please convert this library for the RFDuino?
Thank you so much in advance.
Nikolaus
Hi, im a newbie writing code :'D. Im making an RFID door unlocker. I replace the RGB blinking led by a single white led with awesome fade. Im trying to call some methods I created before to fade a led with easy effects from this great library but im having some difficulties to get it working correctly. I can upload the full code where I have the issue but here's an example:
This is a method i created from a bit modified "example" from wiki:
#include <LEDFader.h>
#define FADE_TIME 1000 //(miliseconds)
#define INTENSITY 200 // Intensity
void fadeLed(){
if (led.is_fading() == false) {
// Fade from 255 - 0
if (led.get_value() == INTENSITY) {
led.fade(0, FADE_TIME);
}
// Fade from 0 - 255
if (led.get_value() == 0) {
delay(200);
led.fade(INTENSITY, FADE_TIME);
}
}
}
When i try to run this:
#include <LEDFader.h>
#define FADE_TIME 1000 //(miliseconds)
#define INTENSITY 200 // Intensity
// Create new LED Fader on pin 5
LEDFader led = LEDFader(5);
void setup() {
fadeLed();
}
void loop() {
led.update();
}
void fadeLed(){
if (led.is_fading() == false) {
// Fade from INTENSITY - 0
if (led.get_value() == INTENSITY) {
led.fade(0, FADE_TIME);
}
// Fade from 0 - INTENSITY
if (led.get_value() == 0) {
delay(200);
led.fade(INTENSITY, FADE_TIME);
}
}
}
I get led fading from 0 to 255 but it gets stuck there. If I call fadeLed()
in void loop()
it works.
I wondering how to run methods like this on void setup()
.
Here's the full code where i have the issue(not complete and in a partial Spanish translation, sorry about that:
https://www.dropbox.com/s/azdpxl1pm2cdlkf/RFID_RC522_Door_LED_BLANCO.ino?dl=0
Heyy,
First, I want to give compliments for this library. For one LED does that really super good.
But now I have a little problem. For a program I would like to use the "fading library." The goal is to, for example, push button C and LED C starts fading. And when i push button B, LED B starts fading. I want this, however, connect to different pins. Do you happen to have a program that does this? The fact I am unable to change your preview of several LEDs.
I look forward to your reaction,
greetings yvette
how to set curve?
Could you please include a working sketch on how you would use the Curve.h feature
Hi,
I like your library very much. Thanks for your work!
You notice in Curve.cpp
:
// If the compiler could build the above table for us, we could have "simply":
// return !i ? 0 : round(exp(log(MAXOUTPUT) * i / MAXINPUT));
I tried it and strangely enough the compiler does not complain, even if these functions are not mentioned in the Arduino reference, But executing this statement gives complete rubbish. Luckily we can replace the functions with their basic equivalents (assuming MAXOUTPUT=MAXINPUT=255
):
log(255)/255
= 0.0217304452751311
exp(x)
= pow(2.71828182845905, x)
round(x)
= int(x + 0.5)
Now we can use
return !i ? 0 : int(pow(2.71828182845905, i * 0.0217304452751311) + 0.5);
and can get rid of that table!
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.