-
Notifications
You must be signed in to change notification settings - Fork 4
/
RGBMood.h
72 lines (67 loc) · 3.39 KB
/
RGBMood.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
71
72
/*
Created by Harold Waterkeyn, February 1, 2012
V0.3 : Feb 4, 2012
Credits:
Inspired from the Moodlight Library by Kasper Kamperman
http://www.kasperkamperman.com/blog/arduino-moodlight-library/
*/
#ifndef GUARD_RGB
#define GUARD_RGB
#include "Arduino.h"
class RGBMood {
public:
enum Modes {
FIX_MODE,
RANDOM_HUE_MODE,
RAINBOW_HUE_MODE,
RED_MODE,
BLUE_MODE,
GREEN_MODE,
FIRE_MODE
};
RGBMood(uint8_t = 0, uint8_t = 0, uint8_t = 0); // New instance with output pin specified.
void setHSB(uint16_t, uint16_t, uint16_t); // Set a fixed color from HSB color space.
void setRGB(uint16_t, uint16_t, uint16_t); // Set a fixed color from RGB color space.
void setRGB(uint32_t); // Using Color class.
void fadeHSB(uint16_t, uint16_t, uint16_t, bool = true); // Fade to a new color (given in HSB color space).
void fadeRGB(uint16_t, uint16_t, uint16_t); // Fade to a new color (given in RGB color space).
void fadeRGB(uint32_t); // Using Color class.
void tick(); // Update colors if needed. (call this in the loop function)
void hsb2rgb(uint16_t, uint16_t, uint16_t, uint16_t&, uint16_t&, uint16_t&); // Used internally to convert HSB to RGB
bool isFading() {return fading_;} // True we are currently fading to a new color.
bool isStill() {return not fading_;} // True if we are not fading to a new color.
void setMode(Modes m) {mode_ = m;} // Change the mode.
void setHoldingTime(uint16_t t) {holding_color_ = t;} // How many ms do we keep a color before fading to a new one.
void setFadingSpeed(uint16_t t) {fading_step_time_ = t;} // How many ms between each step when fading.
void setFadingSteps(uint16_t t) {fading_max_steps_ = t;} // How many steps for fading from a color to another.
uint16_t red() {return current_RGB_color_[0];} // The current red color.
uint16_t green() {return current_RGB_color_[1];} // The current green color.
uint16_t blue() {return current_RGB_color_[2];} // The current blue color.
private:
Modes mode_;
uint8_t pins_[3]; // The pins for color output. (PWM)
uint16_t current_RGB_color_[3];
uint16_t current_HSB_color_[3];
uint16_t initial_color_[3]; // Used when fading.
uint16_t target_color_[3]; // Used when fading.
uint16_t fading_step_; // Current step of the fading.
uint16_t fading_max_steps_; // The total number of steps when fading.
uint16_t fading_step_time_; // The number of ms between two variation of color when fading.
uint16_t holding_color_; // The number of ms to hold color before fading again. (when cycling i.e. mode_ != 0)
// Todo, why not using 2 boundary and random between the 2 ?
bool fading_in_hsb_; // Are we fading between colors in HSB color space ?
bool fading_; // Are we fading now ?
unsigned long last_update_; // Last time we did something.
void fade(); // Used internaly to fade
};
class Color {
public:
static const uint32_t RED = 0xFF0000;
static const uint32_t GREEN = 0x00FF00;
static const uint32_t BLUE = 0x0000FF;
static const uint32_t AQUAMARINE = 0x7FFFD4;
static const uint32_t AIRFORCEBLUE = 0x5D8AA8;
static const uint32_t AMARANTH = 0xE52B50;
static const uint32_t ASPARAGUS = 0x87A96B;
};
#endif