Final Project로 실제 점검에 사용된 코드
Dependencies: mbed Adafruit_GFX
WS2812/WS2812.h@0:22391cd705e2, 2019-06-15 (annotated)
- Committer:
- 21400688
- Date:
- Sat Jun 15 20:52:15 2019 +0000
- Revision:
- 0:22391cd705e2
vb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
21400688 | 0:22391cd705e2 | 1 | /* Copyright (c) 2012 cstyles, MIT License |
21400688 | 0:22391cd705e2 | 2 | * |
21400688 | 0:22391cd705e2 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
21400688 | 0:22391cd705e2 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
21400688 | 0:22391cd705e2 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
21400688 | 0:22391cd705e2 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
21400688 | 0:22391cd705e2 | 7 | * furnished to do so, subject to the following conditions: |
21400688 | 0:22391cd705e2 | 8 | * |
21400688 | 0:22391cd705e2 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
21400688 | 0:22391cd705e2 | 10 | * substantial portions of the Software. |
21400688 | 0:22391cd705e2 | 11 | * |
21400688 | 0:22391cd705e2 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
21400688 | 0:22391cd705e2 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
21400688 | 0:22391cd705e2 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
21400688 | 0:22391cd705e2 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21400688 | 0:22391cd705e2 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
21400688 | 0:22391cd705e2 | 17 | */ |
21400688 | 0:22391cd705e2 | 18 | |
21400688 | 0:22391cd705e2 | 19 | #ifndef WS2812_H |
21400688 | 0:22391cd705e2 | 20 | #define WS2812_H |
21400688 | 0:22391cd705e2 | 21 | |
21400688 | 0:22391cd705e2 | 22 | #include "mbed.h" |
21400688 | 0:22391cd705e2 | 23 | |
21400688 | 0:22391cd705e2 | 24 | #define FRAME_SIZE 24 |
21400688 | 0:22391cd705e2 | 25 | |
21400688 | 0:22391cd705e2 | 26 | //!Library for the WS2812 RGB LED with integrated controller |
21400688 | 0:22391cd705e2 | 27 | /*! |
21400688 | 0:22391cd705e2 | 28 | The WS2812 is controller that is built into a range of LEDs |
21400688 | 0:22391cd705e2 | 29 | */ |
21400688 | 0:22391cd705e2 | 30 | class WS2812 |
21400688 | 0:22391cd705e2 | 31 | { |
21400688 | 0:22391cd705e2 | 32 | public: |
21400688 | 0:22391cd705e2 | 33 | enum BrightnessControl { OFF, GLOBAL, PER_PIXEL }; |
21400688 | 0:22391cd705e2 | 34 | |
21400688 | 0:22391cd705e2 | 35 | /** |
21400688 | 0:22391cd705e2 | 36 | * Constructor |
21400688 | 0:22391cd705e2 | 37 | * |
21400688 | 0:22391cd705e2 | 38 | * @param pin Output pin. Connect to "Din" on the first WS2812 in the strip |
21400688 | 0:22391cd705e2 | 39 | * @param size Number of LEDs in your strip |
21400688 | 0:22391cd705e2 | 40 | * @param zeroHigh How many NOPs to insert to ensure TOH is properly generated. See library description for more information. |
21400688 | 0:22391cd705e2 | 41 | * @param zeroLow How many NOPs to insert to ensure TOL is properly generated. See library description for more information. |
21400688 | 0:22391cd705e2 | 42 | * @param oneHigh How many NOPs to insert to ensure T1H is properly generated. See library description for more information. |
21400688 | 0:22391cd705e2 | 43 | * @param oneLow How many NOPs to insert to ensure T1L is properly generated. See library description for more information. |
21400688 | 0:22391cd705e2 | 44 | * |
21400688 | 0:22391cd705e2 | 45 | */ |
21400688 | 0:22391cd705e2 | 46 | WS2812(PinName pin, int size, int zeroHigh, int zeroLow, int oneHigh, int oneLow); |
21400688 | 0:22391cd705e2 | 47 | |
21400688 | 0:22391cd705e2 | 48 | /*! |
21400688 | 0:22391cd705e2 | 49 | Destroys instance. |
21400688 | 0:22391cd705e2 | 50 | */ |
21400688 | 0:22391cd705e2 | 51 | ~WS2812(); |
21400688 | 0:22391cd705e2 | 52 | |
21400688 | 0:22391cd705e2 | 53 | /** |
21400688 | 0:22391cd705e2 | 54 | * Sets the timing parameters for the bit-banged signal |
21400688 | 0:22391cd705e2 | 55 | * |
21400688 | 0:22391cd705e2 | 56 | * @param zeroHigh How many NOPs to insert to ensure TOH is properly generated. See library description for more information. |
21400688 | 0:22391cd705e2 | 57 | * @param zeroLow How many NOPs to insert to ensure TOL is properly generated. See library description for more information. |
21400688 | 0:22391cd705e2 | 58 | * @param oneHigh How many NOPs to insert to ensure T1H is properly generated. See library description for more information. |
21400688 | 0:22391cd705e2 | 59 | * @param oneLow How many NOPs to insert to ensure T1L is properly generated. See library description for more information. |
21400688 | 0:22391cd705e2 | 60 | * |
21400688 | 0:22391cd705e2 | 61 | */ |
21400688 | 0:22391cd705e2 | 62 | void setDelays(int zeroHigh, int zeroLow, int oneHigh, int oneLow); |
21400688 | 0:22391cd705e2 | 63 | |
21400688 | 0:22391cd705e2 | 64 | /** |
21400688 | 0:22391cd705e2 | 65 | * Writes the given buffer to the LED strip with the given offsets. |
21400688 | 0:22391cd705e2 | 66 | * NOTE: This function is timing critical, therefore interrupts are disabled during the transmission section. |
21400688 | 0:22391cd705e2 | 67 | * |
21400688 | 0:22391cd705e2 | 68 | * @param buf Pointer to the PixelArray buffer |
21400688 | 0:22391cd705e2 | 69 | * @param r_offset The offset where each each pixel pulls its red component. Wraps to beginning if end is reached. |
21400688 | 0:22391cd705e2 | 70 | * @param g_offset The offset where each each pixel pulls its green component. Wraps to beginning if end is reached. |
21400688 | 0:22391cd705e2 | 71 | * @param b_offset The offset where each each pixel pulls its blue component. Wraps to beginning if end is reached. |
21400688 | 0:22391cd705e2 | 72 | * |
21400688 | 0:22391cd705e2 | 73 | */ |
21400688 | 0:22391cd705e2 | 74 | void write_offsets(int buf[], int r_offset = 0, int g_offset = 0, int b_offset = 0); |
21400688 | 0:22391cd705e2 | 75 | |
21400688 | 0:22391cd705e2 | 76 | |
21400688 | 0:22391cd705e2 | 77 | /** |
21400688 | 0:22391cd705e2 | 78 | * Writes the given buffer to the LED strip |
21400688 | 0:22391cd705e2 | 79 | * NOTE: This function is timing critical, therefore interrupts are disabled during the transmission section. |
21400688 | 0:22391cd705e2 | 80 | * |
21400688 | 0:22391cd705e2 | 81 | * @param buf Pointer to the PixelArray buffer |
21400688 | 0:22391cd705e2 | 82 | * |
21400688 | 0:22391cd705e2 | 83 | */ |
21400688 | 0:22391cd705e2 | 84 | void write(int buf[]); |
21400688 | 0:22391cd705e2 | 85 | |
21400688 | 0:22391cd705e2 | 86 | /** |
21400688 | 0:22391cd705e2 | 87 | * Sets the brightness mode |
21400688 | 0:22391cd705e2 | 88 | * |
21400688 | 0:22391cd705e2 | 89 | * @param bc The brightness control. Defaults to OFF. Possible values include OFF, GLOBAL, and PER_PIXEL |
21400688 | 0:22391cd705e2 | 90 | * |
21400688 | 0:22391cd705e2 | 91 | */ |
21400688 | 0:22391cd705e2 | 92 | void useII(BrightnessControl bc); |
21400688 | 0:22391cd705e2 | 93 | |
21400688 | 0:22391cd705e2 | 94 | /** |
21400688 | 0:22391cd705e2 | 95 | * Sets the global brightness level. |
21400688 | 0:22391cd705e2 | 96 | * |
21400688 | 0:22391cd705e2 | 97 | * @param II The brightness level. Possible values include 0 - 255 (0x00 - 0xFF). |
21400688 | 0:22391cd705e2 | 98 | * |
21400688 | 0:22391cd705e2 | 99 | */ |
21400688 | 0:22391cd705e2 | 100 | void setII(unsigned char II); |
21400688 | 0:22391cd705e2 | 101 | |
21400688 | 0:22391cd705e2 | 102 | |
21400688 | 0:22391cd705e2 | 103 | |
21400688 | 0:22391cd705e2 | 104 | private: |
21400688 | 0:22391cd705e2 | 105 | |
21400688 | 0:22391cd705e2 | 106 | int __size; |
21400688 | 0:22391cd705e2 | 107 | int __zeroHigh, __zeroLow, __oneHigh, __oneLow; |
21400688 | 0:22391cd705e2 | 108 | unsigned char __II; |
21400688 | 0:22391cd705e2 | 109 | BrightnessControl __use_II; |
21400688 | 0:22391cd705e2 | 110 | bool *__transmitBuf; |
21400688 | 0:22391cd705e2 | 111 | void __loadBuf(int buf[],int r_offset=0, int g_offset=0, int b_offset=0); |
21400688 | 0:22391cd705e2 | 112 | PinName __outPin; |
21400688 | 0:22391cd705e2 | 113 | DigitalOut __gpo; |
21400688 | 0:22391cd705e2 | 114 | }; |
21400688 | 0:22391cd705e2 | 115 | |
21400688 | 0:22391cd705e2 | 116 | #endif |