Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Nucleo_neopixel_ovgu Nucleo_neopixel_ovgu1 Nucleo_neopixel_ovgu3
Fork of NeoPixel by
neopixel.h@0:a81364d9a67b, 2017-03-21 (annotated)
- Committer:
 - MightyPork
 - Date:
 - Tue Mar 21 21:17:08 2017 +0000
 - Revision:
 - 0:a81364d9a67b
 - Child:
 - 1:037882a8e193
 
initial
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| MightyPork | 0:a81364d9a67b | 1 | #ifndef NEOPIXEL_H | 
| MightyPork | 0:a81364d9a67b | 2 | #define NEOPIXEL_H | 
| MightyPork | 0:a81364d9a67b | 3 | #include "mbed.h" | 
| MightyPork | 0:a81364d9a67b | 4 | |
| MightyPork | 0:a81364d9a67b | 5 | /* | 
| MightyPork | 0:a81364d9a67b | 6 | // Example | 
| MightyPork | 0:a81364d9a67b | 7 | |
| MightyPork | 0:a81364d9a67b | 8 | NeoPixelOut npx(D12); | 
| MightyPork | 0:a81364d9a67b | 9 | |
| MightyPork | 0:a81364d9a67b | 10 | int main() { | 
| MightyPork | 0:a81364d9a67b | 11 | wait(0.2); // wait for HSE to stabilize | 
| MightyPork | 0:a81364d9a67b | 12 | |
| MightyPork | 0:a81364d9a67b | 13 | npx.global_scale = 1.0f; // Adjust brightness | 
| MightyPork | 0:a81364d9a67b | 14 | npx.normalize = true; // Equalize brightness to make r + g + b = 255 | 
| MightyPork | 0:a81364d9a67b | 15 | |
| MightyPork | 0:a81364d9a67b | 16 | Pixel strip[6]; | 
| MightyPork | 0:a81364d9a67b | 17 | strip[0].hex = 0xFF0000; | 
| MightyPork | 0:a81364d9a67b | 18 | strip[1].hex = 0xFFFF00; | 
| MightyPork | 0:a81364d9a67b | 19 | strip[2].hex = 0x00FF00; | 
| MightyPork | 0:a81364d9a67b | 20 | strip[3].hex = 0x00FFFF; | 
| MightyPork | 0:a81364d9a67b | 21 | strip[4].hex = 0x0000FF; | 
| MightyPork | 0:a81364d9a67b | 22 | strip[5].hex = 0xFF00FF; | 
| MightyPork | 0:a81364d9a67b | 23 | |
| MightyPork | 0:a81364d9a67b | 24 | npx.send(strip, 6); | 
| MightyPork | 0:a81364d9a67b | 25 | |
| MightyPork | 0:a81364d9a67b | 26 | while(1); | 
| MightyPork | 0:a81364d9a67b | 27 | } | 
| MightyPork | 0:a81364d9a67b | 28 | */ | 
| MightyPork | 0:a81364d9a67b | 29 | |
| MightyPork | 0:a81364d9a67b | 30 | |
| MightyPork | 0:a81364d9a67b | 31 | |
| MightyPork | 0:a81364d9a67b | 32 | /** | 
| MightyPork | 0:a81364d9a67b | 33 | * @brief Struct for easy manipulation of RGB colors. | 
| MightyPork | 0:a81364d9a67b | 34 | * | 
| MightyPork | 0:a81364d9a67b | 35 | * Set components in the xrgb.r (etc.) and you will get | 
| MightyPork | 0:a81364d9a67b | 36 | * the hex in xrgb.num. | 
| MightyPork | 0:a81364d9a67b | 37 | */ | 
| MightyPork | 0:a81364d9a67b | 38 | union Pixel { | 
| MightyPork | 0:a81364d9a67b | 39 | /** Struct for access to individual color components */ | 
| MightyPork | 0:a81364d9a67b | 40 | struct __attribute__((packed)) { | 
| MightyPork | 0:a81364d9a67b | 41 | uint8_t b; | 
| MightyPork | 0:a81364d9a67b | 42 | uint8_t g; | 
| MightyPork | 0:a81364d9a67b | 43 | uint8_t r; | 
| MightyPork | 0:a81364d9a67b | 44 | uint8_t a; // unused | 
| MightyPork | 0:a81364d9a67b | 45 | }; | 
| MightyPork | 0:a81364d9a67b | 46 | |
| MightyPork | 0:a81364d9a67b | 47 | /** RGB color as a single uint32_t */ | 
| MightyPork | 0:a81364d9a67b | 48 | uint32_t hex; | 
| MightyPork | 0:a81364d9a67b | 49 | }; | 
| MightyPork | 0:a81364d9a67b | 50 | |
| MightyPork | 0:a81364d9a67b | 51 | |
| MightyPork | 0:a81364d9a67b | 52 | class NeoPixelOut : DigitalOut { | 
| MightyPork | 0:a81364d9a67b | 53 | private: | 
| MightyPork | 0:a81364d9a67b | 54 | void byte(uint32_t b); | 
| MightyPork | 0:a81364d9a67b | 55 | |
| MightyPork | 0:a81364d9a67b | 56 | public: | 
| MightyPork | 0:a81364d9a67b | 57 | bool normalize; | 
| MightyPork | 0:a81364d9a67b | 58 | float global_scale; | 
| MightyPork | 0:a81364d9a67b | 59 | |
| MightyPork | 0:a81364d9a67b | 60 | NeoPixelOut(PinName pin); | 
| MightyPork | 0:a81364d9a67b | 61 | |
| MightyPork | 0:a81364d9a67b | 62 | void send(Pixel *colors, uint32_t count, bool flipwait=true); | 
| MightyPork | 0:a81364d9a67b | 63 | |
| MightyPork | 0:a81364d9a67b | 64 | /** Wait long enough to make the colors show up */ | 
| MightyPork | 0:a81364d9a67b | 65 | void flip(void); | 
| MightyPork | 0:a81364d9a67b | 66 | }; | 
| MightyPork | 0:a81364d9a67b | 67 | |
| MightyPork | 0:a81364d9a67b | 68 | |
| MightyPork | 0:a81364d9a67b | 69 | #endif /* NEOPIXEL_H */ | 
