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.
ws2812B.hpp
- Committer:
- MikamiUitOpen
- Date:
- 2016-09-24
- Revision:
- 1:2d0f84d78ca2
- Parent:
- 0:160ed7a225a4
- Child:
- 2:2d4f2cc38f87
File content as of revision 1:2d0f84d78ca2:
//----------------------------------------------------
// SPI を使って WS2812B を点灯するためのクラス(ヘッダ)
// サポートしているボード
// Nucleo-F401RE, Nucleo-F446RE
// 2016/09/24, Copyright (c) 2016 MIKAMI, Naoki
//----------------------------------------------------
#include "mbed.h"
#if !defined(STM32F401xE) && !defined(STM32F446xx)
#error Select STM32F401 or STM32F446.
#endif
#ifndef STM32F4xx_WS2812B_HPP
#define STM32F4xx_WS2812B_HPP
namespace Mikami
{
class WS2812B
{
public:
// コンストラクタ
// inv = true: インバータを介して WS2812B に接続する場合
// = false: 直接 WS2812B に接続する場合
WS2812B(PinName pin, bool inv = false);
void Write(uint32_t x); // 一つの LED へ書き込む
void Reset(); // 一連の書き込みの最後に実行する
void Clear(int k); // k 個の LED を消灯
private:
SPI_TypeDef *mySpi_;
void (WS2812B::*fp)(uint8_t);
void SendByte(uint8_t x) { (this->*fp)(x); }
void Send3Bytes(uint8_t x0, uint8_t x1, uint8_t x2);
void T0HL() { Send3Bytes(0xFE, 0x00, 0x00); } // 0 を送る
void T1HL() { Send3Bytes(0xFF, 0xFF, 0x00); } // 1 を送る
void Dummy() { SendByte(0x00); }
void SendByteNrm(uint8_t x); // データをそのまま送る
void SendByteInv(uint8_t x); // データを反転して送る
};
}
#endif // STM32F4xx_WS2812B_HPP