Library and demo using the WS2812-based Neopixel strip connected to an LPC114
Fork of LEDTape_WS2812 by
Details here: http://mbed.org/users/rhodes42/notebook/tiny-neopixel-controller-with-lpc1114/
LEDStripFunctions.cpp@3:743570d993aa, 2014-04-08 (annotated)
- Committer:
- rhodes42
- Date:
- Tue Apr 08 20:56:03 2014 +0000
- Revision:
- 3:743570d993aa
- Parent:
- 2:61abc599f31f
added scalebrightness and changed main demo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rhodes42 | 2:61abc599f31f | 1 | #include "mbed.h" |
rhodes42 | 2:61abc599f31f | 2 | #include "LEDStrip.h" |
rhodes42 | 2:61abc599f31f | 3 | #include <stdint.h> |
rhodes42 | 2:61abc599f31f | 4 | |
rhodes42 | 2:61abc599f31f | 5 | |
rhodes42 | 2:61abc599f31f | 6 | void setAll(uint32_t *buffer, int n) |
rhodes42 | 2:61abc599f31f | 7 | { |
rhodes42 | 2:61abc599f31f | 8 | int i; |
rhodes42 | 2:61abc599f31f | 9 | for (i = 0; i < n; i++) |
rhodes42 | 2:61abc599f31f | 10 | { |
rhodes42 | 2:61abc599f31f | 11 | tapeSet(i, buffer[i]); |
rhodes42 | 2:61abc599f31f | 12 | } |
rhodes42 | 2:61abc599f31f | 13 | } |
rhodes42 | 2:61abc599f31f | 14 | |
rhodes42 | 2:61abc599f31f | 15 | void setAllOneColor(uint32_t color, int n) |
rhodes42 | 2:61abc599f31f | 16 | { |
rhodes42 | 2:61abc599f31f | 17 | int i; |
rhodes42 | 2:61abc599f31f | 18 | for (i = 0; i < n; i++) |
rhodes42 | 2:61abc599f31f | 19 | { |
rhodes42 | 2:61abc599f31f | 20 | tapeSet(i, color); |
rhodes42 | 2:61abc599f31f | 21 | } |
rhodes42 | 2:61abc599f31f | 22 | } |
rhodes42 | 2:61abc599f31f | 23 | |
rhodes42 | 2:61abc599f31f | 24 | void shiftAllFwd(uint32_t *buffer, int n) |
rhodes42 | 2:61abc599f31f | 25 | { |
rhodes42 | 2:61abc599f31f | 26 | int i; |
rhodes42 | 2:61abc599f31f | 27 | uint32_t temp = buffer[n]; |
rhodes42 | 2:61abc599f31f | 28 | for (i = n; i > 0; i--) |
rhodes42 | 2:61abc599f31f | 29 | { |
rhodes42 | 2:61abc599f31f | 30 | buffer[i] = buffer[i-1]; |
rhodes42 | 2:61abc599f31f | 31 | } |
rhodes42 | 2:61abc599f31f | 32 | buffer[0] = temp; |
rhodes42 | 2:61abc599f31f | 33 | } |
rhodes42 | 2:61abc599f31f | 34 | |
rhodes42 | 2:61abc599f31f | 35 | void shiftAllRev(uint32_t *buffer, int n) |
rhodes42 | 2:61abc599f31f | 36 | { |
rhodes42 | 2:61abc599f31f | 37 | int i; |
rhodes42 | 2:61abc599f31f | 38 | uint32_t temp = buffer[0]; |
rhodes42 | 2:61abc599f31f | 39 | for (i = 0; i <= n-1; i++) |
rhodes42 | 2:61abc599f31f | 40 | { |
rhodes42 | 2:61abc599f31f | 41 | buffer[i] = buffer[i+1]; |
rhodes42 | 2:61abc599f31f | 42 | } |
rhodes42 | 2:61abc599f31f | 43 | buffer[n] = temp; |
rhodes42 | 2:61abc599f31f | 44 | } |
rhodes42 | 2:61abc599f31f | 45 | |
rhodes42 | 2:61abc599f31f | 46 | |
rhodes42 | 2:61abc599f31f | 47 | void setEveryMod(uint32_t * buffer, uint32_t color, int mod, int start, int n) |
rhodes42 | 2:61abc599f31f | 48 | { |
rhodes42 | 2:61abc599f31f | 49 | int i; |
rhodes42 | 2:61abc599f31f | 50 | for (i = 0; i < n; i ++) |
rhodes42 | 2:61abc599f31f | 51 | { |
rhodes42 | 2:61abc599f31f | 52 | if ((i >= start) && ((i - start) % mod == 0)) buffer[i] = color; |
rhodes42 | 2:61abc599f31f | 53 | } |
rhodes42 | 3:743570d993aa | 54 | } |
rhodes42 | 3:743570d993aa | 55 | |
rhodes42 | 3:743570d993aa | 56 | |
rhodes42 | 3:743570d993aa | 57 | void scaleBrightness(uint32_t *buffer, int divider, int n) |
rhodes42 | 3:743570d993aa | 58 | { |
rhodes42 | 3:743570d993aa | 59 | int i, r, g, b; |
rhodes42 | 3:743570d993aa | 60 | for (i = 0; i < n; i++) |
rhodes42 | 3:743570d993aa | 61 | { |
rhodes42 | 3:743570d993aa | 62 | r = (buffer[i] >> 16) & 0xff; |
rhodes42 | 3:743570d993aa | 63 | g = (buffer[i] >> 8 ) & 0xff; |
rhodes42 | 3:743570d993aa | 64 | b = (buffer[i] ) & 0xff; |
rhodes42 | 3:743570d993aa | 65 | r /= divider; |
rhodes42 | 3:743570d993aa | 66 | g /= divider; |
rhodes42 | 3:743570d993aa | 67 | b /= divider; |
rhodes42 | 3:743570d993aa | 68 | buffer[i] = (r << 16) | (g << 8) | (b); |
rhodes42 | 3:743570d993aa | 69 | } |
rhodes42 | 3:743570d993aa | 70 | } |
rhodes42 | 3:743570d993aa | 71 | |
rhodes42 | 3:743570d993aa | 72 | void setPixelRGB(int pixel, int r, int g, int b) |
rhodes42 | 3:743570d993aa | 73 | { |
rhodes42 | 3:743570d993aa | 74 | |
rhodes42 | 3:743570d993aa | 75 | int pix = (r << 16) | (g << 8) | (b); |
rhodes42 | 3:743570d993aa | 76 | tapeSet(pixel, pix); |
rhodes42 | 2:61abc599f31f | 77 | } |