API追加ver
Fork of NeoStrip by
NeoStrip.h@2:649f6dee76a6, 2016-03-01 (annotated)
- Committer:
- poipoi
- Date:
- Tue Mar 01 06:17:48 2016 +0000
- Revision:
- 2:649f6dee76a6
- Parent:
- 0:9f237b11f0a8
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aswild | 0:9f237b11f0a8 | 1 | /** |
aswild | 0:9f237b11f0a8 | 2 | * NeoStrip.h |
aswild | 0:9f237b11f0a8 | 3 | * |
aswild | 0:9f237b11f0a8 | 4 | * Allen Wild |
aswild | 0:9f237b11f0a8 | 5 | * March 2014 |
aswild | 0:9f237b11f0a8 | 6 | * |
aswild | 0:9f237b11f0a8 | 7 | * Library for the control of Adafruit NeoPixel addressable RGB LEDs. |
aswild | 0:9f237b11f0a8 | 8 | */ |
aswild | 0:9f237b11f0a8 | 9 | |
aswild | 0:9f237b11f0a8 | 10 | |
aswild | 0:9f237b11f0a8 | 11 | #ifndef NEOSTRIP_H |
aswild | 0:9f237b11f0a8 | 12 | #define NEOSTRIP_H |
aswild | 0:9f237b11f0a8 | 13 | |
aswild | 0:9f237b11f0a8 | 14 | #ifndef TARGET_LPC1768 |
aswild | 0:9f237b11f0a8 | 15 | #error NeoStrip only supports the NXP LPC1768! |
aswild | 0:9f237b11f0a8 | 16 | #endif |
aswild | 0:9f237b11f0a8 | 17 | |
aswild | 0:9f237b11f0a8 | 18 | // NeoColor struct definition to hold 24 bit |
aswild | 0:9f237b11f0a8 | 19 | // color data for each pixel, in GRB order |
aswild | 0:9f237b11f0a8 | 20 | typedef struct _NeoColor |
aswild | 0:9f237b11f0a8 | 21 | { |
aswild | 0:9f237b11f0a8 | 22 | uint8_t green; |
aswild | 0:9f237b11f0a8 | 23 | uint8_t red; |
aswild | 0:9f237b11f0a8 | 24 | uint8_t blue; |
aswild | 0:9f237b11f0a8 | 25 | } NeoColor; |
aswild | 0:9f237b11f0a8 | 26 | |
aswild | 0:9f237b11f0a8 | 27 | /** |
aswild | 0:9f237b11f0a8 | 28 | * NeoStrip objects manage the buffering and assigning of |
aswild | 0:9f237b11f0a8 | 29 | * addressable NeoPixels |
aswild | 0:9f237b11f0a8 | 30 | */ |
aswild | 0:9f237b11f0a8 | 31 | class NeoStrip |
aswild | 0:9f237b11f0a8 | 32 | { |
aswild | 0:9f237b11f0a8 | 33 | public: |
aswild | 0:9f237b11f0a8 | 34 | |
aswild | 0:9f237b11f0a8 | 35 | /** |
aswild | 0:9f237b11f0a8 | 36 | * Create a NeoStrip object |
aswild | 0:9f237b11f0a8 | 37 | * |
aswild | 0:9f237b11f0a8 | 38 | * @param pin The mbed data pin name |
aswild | 0:9f237b11f0a8 | 39 | * @param N The number of pixels in the strip |
aswild | 0:9f237b11f0a8 | 40 | */ |
aswild | 0:9f237b11f0a8 | 41 | NeoStrip(PinName pin, int N); |
aswild | 0:9f237b11f0a8 | 42 | |
aswild | 0:9f237b11f0a8 | 43 | /** |
aswild | 0:9f237b11f0a8 | 44 | * Set an overall brightness scale for the entire strip. |
aswild | 0:9f237b11f0a8 | 45 | * When colors are set using setPixel(), they are scaled |
aswild | 0:9f237b11f0a8 | 46 | * according to this brightness. |
aswild | 0:9f237b11f0a8 | 47 | * |
aswild | 0:9f237b11f0a8 | 48 | * Because NeoPixels are very bright and draw a lot of current, |
aswild | 0:9f237b11f0a8 | 49 | * the brightness is set to 0.5 by default. |
aswild | 0:9f237b11f0a8 | 50 | * |
aswild | 0:9f237b11f0a8 | 51 | * @param bright The brightness scale between 0 and 1.0 |
aswild | 0:9f237b11f0a8 | 52 | */ |
aswild | 0:9f237b11f0a8 | 53 | void setBrightness(float bright); |
aswild | 0:9f237b11f0a8 | 54 | |
aswild | 0:9f237b11f0a8 | 55 | /** |
aswild | 0:9f237b11f0a8 | 56 | * Set a single pixel to the specified color. |
aswild | 0:9f237b11f0a8 | 57 | * |
aswild | 0:9f237b11f0a8 | 58 | * This method (and all other setPixel methods) uses modulo-N arithmetic |
aswild | 0:9f237b11f0a8 | 59 | * when addressing pixels. If p >= N, the pixel address will wrap around. |
aswild | 0:9f237b11f0a8 | 60 | * |
aswild | 0:9f237b11f0a8 | 61 | * @param p The pixel number (starting at 0) to set |
aswild | 0:9f237b11f0a8 | 62 | * @param color A 24-bit color packed into a single int, |
aswild | 0:9f237b11f0a8 | 63 | * using standard hex color codes (e.g. 0xFF0000 is red) |
aswild | 0:9f237b11f0a8 | 64 | */ |
aswild | 0:9f237b11f0a8 | 65 | void setPixel(int p, int color); |
aswild | 0:9f237b11f0a8 | 66 | |
aswild | 0:9f237b11f0a8 | 67 | /** |
aswild | 0:9f237b11f0a8 | 68 | * Set a single pixel to the specified color, with red, green, and blue |
aswild | 0:9f237b11f0a8 | 69 | * values in separate arguments. |
aswild | 0:9f237b11f0a8 | 70 | */ |
aswild | 0:9f237b11f0a8 | 71 | void setPixel(int p, uint8_t red, uint8_t green, uint8_t blue); |
aswild | 0:9f237b11f0a8 | 72 | |
aswild | 0:9f237b11f0a8 | 73 | /** |
aswild | 0:9f237b11f0a8 | 74 | * Set n pixels starting at pixel p. |
aswild | 0:9f237b11f0a8 | 75 | * |
aswild | 0:9f237b11f0a8 | 76 | * @param p The first pixel in the strip to set. |
aswild | 0:9f237b11f0a8 | 77 | * @param n The number of pixels to set. |
aswild | 0:9f237b11f0a8 | 78 | * @param colors An array of length n containing the 24-bit colors for each pixel |
aswild | 0:9f237b11f0a8 | 79 | */ |
aswild | 0:9f237b11f0a8 | 80 | void setPixels(int p, int n, const int *colors); |
aswild | 0:9f237b11f0a8 | 81 | |
aswild | 0:9f237b11f0a8 | 82 | /** |
aswild | 0:9f237b11f0a8 | 83 | * Reset all pixels in the strip to be of (0x000000) |
aswild | 0:9f237b11f0a8 | 84 | */ |
aswild | 0:9f237b11f0a8 | 85 | void clear(); |
aswild | 0:9f237b11f0a8 | 86 | |
aswild | 0:9f237b11f0a8 | 87 | /** |
aswild | 0:9f237b11f0a8 | 88 | * Write the colors out to the strip; this method must be called |
aswild | 0:9f237b11f0a8 | 89 | * to see any hardware effect. |
aswild | 0:9f237b11f0a8 | 90 | * |
aswild | 0:9f237b11f0a8 | 91 | * This function disables interrupts while the strip data is being sent, |
aswild | 0:9f237b11f0a8 | 92 | * each pixel takes approximately 30us to send, plus a 50us reset pulse |
aswild | 0:9f237b11f0a8 | 93 | * at the end. |
aswild | 0:9f237b11f0a8 | 94 | */ |
aswild | 0:9f237b11f0a8 | 95 | void write(); |
poipoi | 2:649f6dee76a6 | 96 | |
poipoi | 2:649f6dee76a6 | 97 | void setPixels(int p, int n, uint8_t *p_buff); |
aswild | 0:9f237b11f0a8 | 98 | |
aswild | 0:9f237b11f0a8 | 99 | protected: |
aswild | 0:9f237b11f0a8 | 100 | NeoColor *strip; // pixel data buffer modified by setPixel() and used by neo_out() |
aswild | 0:9f237b11f0a8 | 101 | int N; // the number of pixels in the strip |
aswild | 0:9f237b11f0a8 | 102 | int Nbytes; // the number of bytes of pixel data (always N*3) |
aswild | 0:9f237b11f0a8 | 103 | float bright; // the master strip brightness |
aswild | 0:9f237b11f0a8 | 104 | gpio_t gpio; // gpio struct for initialization and getting register addresses |
aswild | 0:9f237b11f0a8 | 105 | }; |
aswild | 0:9f237b11f0a8 | 106 | |
aswild | 0:9f237b11f0a8 | 107 | #endif |
aswild | 0:9f237b11f0a8 | 108 | |
aswild | 0:9f237b11f0a8 | 109 |