-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sample/rain: simulated rain drops which fade over time
- Loading branch information
1 parent
3329e00
commit 5d1316c
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*! \file fade.config | ||
* | ||
* \brief Coordinated up/down fading configuration | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/* | ||
* This macro defines the PWM channels of each participating LED. | ||
* | ||
* The fade engine calculates a PWM setting in the range 0..255 according | ||
* to the master PWM target, the current PWM setting and the rate of change | ||
* | ||
* A selector macro is passed which will choose a parameter from the | ||
* configuration. For example, if you want to control PWM channels 1, 0 and 3 | ||
* use the macro like this | ||
* | ||
* @code | ||
* #define FADE_PWMS(_) _(1) _(0) _(3) | ||
* @endcode | ||
*/ | ||
|
||
#define FADE_PWMS(_) _(0) _(1) _(2) _(3) _(4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/*! \file pwm.config | ||
* | ||
* \brief Software Pulse Width Modulation configuration | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
/* | ||
* This macro defines the GPIOs configured to be used as PWM outputs. | ||
* | ||
* A selector macro is passed which will choose a parameter from the | ||
* configuration. For example, if you want to set PB5 and PB2 to be | ||
* PWM channels 0 and 1 respectively use the macro like this | ||
* | ||
* @code | ||
* #define PWM_GPIOS(_) _(B, 5) _(B, 2) | ||
* @endcode | ||
*/ | ||
|
||
#define PWM_GPIOS(_) _(B, 0) _(B, 1) _(B, 2) _(B, 3) _(B, 4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/*! \file rain.c | ||
* | ||
* \brief Rain effect on LEDs | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "task.h" | ||
#include "fade.h" | ||
#include "pwm.h" | ||
#include "random.h" | ||
|
||
#include <stdint.h> | ||
|
||
#define RAIN_TICK 100 | ||
#define RAIN_DISPERSE 80 | ||
#define RAIN_SPREAD 50 | ||
|
||
static uint8_t rain_task(uint8_t ms_later) | ||
{ | ||
static uint8_t wait; | ||
|
||
switch(ms_later) | ||
{ | ||
case TASK_STARTUP: | ||
wait = 0; | ||
/* Fade to black */ | ||
fade_set_brightness(0); | ||
fade_set_update(RAIN_DISPERSE); | ||
fade_set_rate_linear(8); | ||
break; | ||
case TASK_SHUTDOWN: | ||
break; | ||
default: | ||
wait += ms_later; | ||
if (wait >= RAIN_TICK) | ||
{ | ||
/* pwm_set() ignores addressing a non-existent channel */ | ||
pwm_set(random_get(RAIN_SPREAD), 255); | ||
wait = 0; | ||
} | ||
break; | ||
} | ||
|
||
return RAIN_TICK-wait; | ||
} | ||
|
||
TASK_DECLARE(rain_task); |