forked from jgillick/arduino-LEDFader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLEDFader.h
70 lines (51 loc) · 1.67 KB
/
LEDFader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* LED.h
*
* Created on: Sep 24, 2013
* Author: jeremy
*/
#include "Arduino.h"
#ifndef LEDFader_H_
#define LEDFader_H_
// The minimum time (milliseconds) the program will wait between LED adjustments
// adjust this to modify performance.
#define MIN_INTERVAL 20
#define PWM_PIN NULL
class LEDFader {
void (*do_pwm)(uint8_t channel, uint8_t value);
uint8_t pin;
unsigned long last_step_time;
unsigned int interval;
uint8_t color;
uint8_t to_color;
unsigned int duration;
float percent_done;
public:
// Create a new LED Fader for a pin
LEDFader(uint8_t pwm_pin=0);
// Create a new LED Fader with a helper function
LEDFader(void (*helper)(uint8_t channel, uint8_t value), uint8_t pwm_pin=0);
// Set the PWM pin that the LED is connected to
void set_pin(uint8_t pwm_pin);
uint8_t get_pin();
// Set an LED to an absolute PWM value
void set_value(int pwm);
// Get the current LED PWM value
uint8_t get_value();
// Fade an LED to a PWM value over a duration of time (milliseconds)
void fade(uint8_t pwm, unsigned int time);
// Returns TRUE if there is an active fade process
bool is_fading();
// Stop the current fade where it's at
void stop_fade();
// Update the LEDs along the fade
// Returns TRUE if a fade is still in process
bool update();
// Decrease the current fading speed by a number of milliseconds
void slower(int by_seconds);
// Increase the current fading speed by a number of milliseconds
void faster(int by_seconds);
// Returns how much of the fade is complete in a percentage between 0 - 100
uint8_t get_progress();
};
#endif /* LEDFader_H_ */