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.
WS281XU.h
00001 /* WS281XU.h (for LPC82X/STM32F0x/STM32F446/STM32F746xx) 00002 * mbed Microcontroller Library 00003 * Copyright (c) 2016 muetch, t.kuroki 00004 * Allrights reserved. 00005 * 00006 * Rev 0.97 2016-09-07 00007 * Rev 0.98 2016-09-08 00008 */ 00009 00010 #pragma once 00011 00012 #ifndef WS281XU_H 00013 #define WS281XU_H 00014 00015 //#include "mbed.h" 00016 #include "PixelBuffer.h" 00017 00018 //---------------------------------------------------------------------------- 00019 /** 00020 * WS281XU 00021 */ 00022 class WS281XU : public RGBPixels 00023 { 00024 public: 00025 /** 00026 Order of r, g and b bytes 00027 */ 00028 enum RGBOrder 00029 { 00030 RGB = 0, RBG, GRB, GBR, BRG, BGR 00031 }; 00032 00033 /** 00034 * Initializes the addressable led bus 00035 * 00036 * @param txPin - The output pin on wich the addressable leds are connected 00037 * @param pinMode - The output pin mode PullUp, PullDown, PullNone, OpenDrain 00038 * @param maxPixels - Number of the addressable leds 00039 * @param RGBOrder - The order in wich the r, g and b bytes are expected 00040 */ 00041 WS281XU(PinName txPin, PinMode pinMode = PullNone, int maxPixels = MAX_PIXELS, RGBOrder rgbOrder = WS281XU::RGB); 00042 WS281XU(PinName txPin, PinMode pinMode = PullNone, RGBColor *buffer = 0, int maxPixels = 0, RGBOrder rgbOrder = WS281XU::RGB); 00043 virtual ~WS281XU(); 00044 00045 RGBOrder rgbOrder() { return _rgb_order; } 00046 RGBOrder rgbOrder(RGBOrder order); 00047 00048 void show(); 00049 void show(const RGBColor color); 00050 00051 bool irqEnabled() { return _irq_enabled; } 00052 bool irqEnabled(bool value) { return _irq_enabled = value; } 00053 00054 RGBColor operator[](int index) const 00055 { 00056 if (_pixels && (uint16_t)index < _num_pixels) 00057 return _pixels[index]; 00058 return _dummy_pixel; 00059 } 00060 00061 RGBColor& operator[](int index) 00062 { 00063 if (_pixels && (uint16_t)index < _num_pixels) 00064 return _pixels[index]; 00065 return _dummy_pixel; 00066 } 00067 00068 operator RGBColor*() const { return _pixels; } 00069 00070 protected: 00071 void putByte(uint8_t c) { serial_putc(&_serial, c); } 00072 00073 private: 00074 PinName _txPin; 00075 serial_t _serial; 00076 bool _irq_enabled; 00077 RGBOrder _rgb_order; 00078 int _1st, _2nd, _3rd; 00079 00080 #if defined(TARGET_STM) 00081 void pin_mode_ex(PinName pin, PinMode mode); 00082 #endif 00083 void pin_init(PinName txPin, PinMode pinMode); 00084 }; 00085 00086 //---------------------------------------------------------------------------- 00087 #endif // end of WS281XU_H
Generated on Thu Jul 14 2022 04:31:44 by
