Example of DDBooster library usage showing a falling water drop effect.
Dependencies: DD-Booster-mbed mbed
main.cpp@0:3a382b72adfb, 2017-03-06 (annotated)
- Committer:
- Gamadril
- Date:
- Mon Mar 06 13:43:12 2017 +0000
- Revision:
- 0:3a382b72adfb
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Gamadril | 0:3a382b72adfb | 1 | #include "DDBooster.h" |
Gamadril | 0:3a382b72adfb | 2 | |
Gamadril | 0:3a382b72adfb | 3 | #define LEDS 20 |
Gamadril | 0:3a382b72adfb | 4 | |
Gamadril | 0:3a382b72adfb | 5 | int main() |
Gamadril | 0:3a382b72adfb | 6 | { |
Gamadril | 0:3a382b72adfb | 7 | // get the instance of DDBooster with configured SPI pins |
Gamadril | 0:3a382b72adfb | 8 | DDBooster booster(SPI_MOSI, SPI_SCK, SPI_CS); |
Gamadril | 0:3a382b72adfb | 9 | |
Gamadril | 0:3a382b72adfb | 10 | // tell the number of LEDs used |
Gamadril | 0:3a382b72adfb | 11 | booster.init(LEDS); |
Gamadril | 0:3a382b72adfb | 12 | |
Gamadril | 0:3a382b72adfb | 13 | // we start outside from -8 to 0. first led has always index 0 |
Gamadril | 0:3a382b72adfb | 14 | // both values define the length of the drop |
Gamadril | 0:3a382b72adfb | 15 | int16_t start = -8, end = 0; |
Gamadril | 0:3a382b72adfb | 16 | // show a gradient from white to blue |
Gamadril | 0:3a382b72adfb | 17 | uint8_t startColor[] = {60, 60, 60}; |
Gamadril | 0:3a382b72adfb | 18 | uint8_t endColor[] = {0, 0, 60}; |
Gamadril | 0:3a382b72adfb | 19 | |
Gamadril | 0:3a382b72adfb | 20 | while(1) { |
Gamadril | 0:3a382b72adfb | 21 | // turn all leds off |
Gamadril | 0:3a382b72adfb | 22 | booster.clearAll(); |
Gamadril | 0:3a382b72adfb | 23 | // set gradient with current values |
Gamadril | 0:3a382b72adfb | 24 | booster.setGradient(start, end, startColor, endColor); |
Gamadril | 0:3a382b72adfb | 25 | // commit it |
Gamadril | 0:3a382b72adfb | 26 | booster.show(); |
Gamadril | 0:3a382b72adfb | 27 | |
Gamadril | 0:3a382b72adfb | 28 | // when the start index runs out of visible area (last led has index led_count - 1) |
Gamadril | 0:3a382b72adfb | 29 | // start from the beginning, otherwise increment the start and end postitions |
Gamadril | 0:3a382b72adfb | 30 | if (start == LEDS) { |
Gamadril | 0:3a382b72adfb | 31 | start = -8; |
Gamadril | 0:3a382b72adfb | 32 | end = 0; |
Gamadril | 0:3a382b72adfb | 33 | // delay between the drops |
Gamadril | 0:3a382b72adfb | 34 | wait_ms(1000); |
Gamadril | 0:3a382b72adfb | 35 | } else { |
Gamadril | 0:3a382b72adfb | 36 | start++; |
Gamadril | 0:3a382b72adfb | 37 | end++; |
Gamadril | 0:3a382b72adfb | 38 | } |
Gamadril | 0:3a382b72adfb | 39 | |
Gamadril | 0:3a382b72adfb | 40 | // changing the value makes the drop fall faster or slower |
Gamadril | 0:3a382b72adfb | 41 | wait_ms(20); |
Gamadril | 0:3a382b72adfb | 42 | } |
Gamadril | 0:3a382b72adfb | 43 | } |