Light Show library for organic, calm, light display.
Dependencies: BLE_API mbed nRF51822
Fork of mbed_blinky by
light_show.h@27:a55dde8334f3, 2016-02-01 (annotated)
- Committer:
- nargetdev
- Date:
- Mon Feb 01 02:45:51 2016 +0000
- Revision:
- 27:a55dde8334f3
- Parent:
- 26:8bc9984c4600
light_show library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nargetdev | 27:a55dde8334f3 | 1 | /*LED driver library for an "organic" light show, a composition of sine waves. |
nargetdev | 27:a55dde8334f3 | 2 | * |
nargetdev | 27:a55dde8334f3 | 3 | * by Nate Argetsinger |
nargetdev | 27:a55dde8334f3 | 4 | * |
nargetdev | 27:a55dde8334f3 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
nargetdev | 27:a55dde8334f3 | 6 | * of this software and associated documentation files (the "Software"), to deal |
nargetdev | 27:a55dde8334f3 | 7 | * in the Software without restriction, including without limitation the rights |
nargetdev | 27:a55dde8334f3 | 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
nargetdev | 27:a55dde8334f3 | 9 | * copies of the Software, and to permit persons to whom the Software is |
nargetdev | 27:a55dde8334f3 | 10 | * furnished to do so, subject to the following conditions: Buy me a beer. |
nargetdev | 27:a55dde8334f3 | 11 | * |
nargetdev | 27:a55dde8334f3 | 12 | * The above copyright notice and this permission notice shall be included in |
nargetdev | 27:a55dde8334f3 | 13 | * all copies or substantial portions of the Software. |
nargetdev | 27:a55dde8334f3 | 14 | * |
nargetdev | 27:a55dde8334f3 | 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
nargetdev | 27:a55dde8334f3 | 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
nargetdev | 27:a55dde8334f3 | 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
nargetdev | 27:a55dde8334f3 | 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
nargetdev | 27:a55dde8334f3 | 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
nargetdev | 27:a55dde8334f3 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
nargetdev | 27:a55dde8334f3 | 21 | * THE SOFTWARE. |
nargetdev | 27:a55dde8334f3 | 22 | */ |
nargetdev | 27:a55dde8334f3 | 23 | |
nargetdev | 27:a55dde8334f3 | 24 | |
nargetdev | 24:52319c0a14b8 | 25 | #ifndef LIGHT_SHOW_H |
nargetdev | 24:52319c0a14b8 | 26 | #define LIGHT_SHOW_H |
nargetdev | 24:52319c0a14b8 | 27 | |
nargetdev | 25:d48f46d753fd | 28 | #include "macros.h" |
nargetdev | 25:d48f46d753fd | 29 | #include "config.h" |
nargetdev | 25:d48f46d753fd | 30 | #include "utility.h" |
nargetdev | 25:d48f46d753fd | 31 | |
nargetdev | 25:d48f46d753fd | 32 | #include "rgb_led.h" |
nargetdev | 25:d48f46d753fd | 33 | #include "sinusoid.h" |
nargetdev | 25:d48f46d753fd | 34 | |
nargetdev | 25:d48f46d753fd | 35 | extern Serial pc; |
nargetdev | 25:d48f46d753fd | 36 | |
nargetdev | 26:8bc9984c4600 | 37 | const float HYSTERESIS_QUANTITY = PI*2; |
nargetdev | 26:8bc9984c4600 | 38 | const float INCREMENT = 0.00628f * 2; |
nargetdev | 25:d48f46d753fd | 39 | |
nargetdev | 24:52319c0a14b8 | 40 | class LightShow |
nargetdev | 24:52319c0a14b8 | 41 | { |
nargetdev | 24:52319c0a14b8 | 42 | public: |
nargetdev | 25:d48f46d753fd | 43 | LightShow(Rgb*); |
nargetdev | 26:8bc9984c4600 | 44 | |
nargetdev | 26:8bc9984c4600 | 45 | /* randomize parameters of the 3 sine waves */ |
nargetdev | 24:52319c0a14b8 | 46 | void randomize_params(); |
nargetdev | 25:d48f46d753fd | 47 | |
nargetdev | 26:8bc9984c4600 | 48 | /* Displays light show. |
nargetdev | 26:8bc9984c4600 | 49 | * The light show is a composition of 3 sine waves for 3 channel LEDs |
nargetdev | 26:8bc9984c4600 | 50 | **/ |
nargetdev | 25:d48f46d753fd | 51 | void show(); |
nargetdev | 26:8bc9984c4600 | 52 | |
nargetdev | 26:8bc9984c4600 | 53 | /** sanity check for debugging **/ |
nargetdev | 26:8bc9984c4600 | 54 | void simple_show(); |
nargetdev | 25:d48f46d753fd | 55 | |
nargetdev | 25:d48f46d753fd | 56 | private: |
nargetdev | 25:d48f46d753fd | 57 | Rgb* strip; |
nargetdev | 25:d48f46d753fd | 58 | Sinusoid sine_waves[3]; |
nargetdev | 24:52319c0a14b8 | 59 | |
nargetdev | 25:d48f46d753fd | 60 | // get some randomness |
nargetdev | 25:d48f46d753fd | 61 | Timer t; |
nargetdev | 25:d48f46d753fd | 62 | |
nargetdev | 24:52319c0a14b8 | 63 | static const float HYSTERESIS_QUANTITY = PI/4; |
nargetdev | 24:52319c0a14b8 | 64 | |
nargetdev | 25:d48f46d753fd | 65 | float time; // phase |
nargetdev | 25:d48f46d753fd | 66 | uint8_t finished; // bit mask for smooth fade out |
nargetdev | 25:d48f46d753fd | 67 | float hysteresis; |
nargetdev | 25:d48f46d753fd | 68 | float rgb_c[3]; |
nargetdev | 24:52319c0a14b8 | 69 | |
nargetdev | 25:d48f46d753fd | 70 | void update_rgb(); |
nargetdev | 24:52319c0a14b8 | 71 | }; |
nargetdev | 24:52319c0a14b8 | 72 | |
nargetdev | 24:52319c0a14b8 | 73 | #endif |