WS2812B Liblary this use SPI

Committer:
Suzutomo
Date:
Sun Jun 30 08:26:25 2019 +0000
Revision:
3:c0a82b9775e6
Parent:
2:b472bd90c6ce
Child:
4:02e88df0ae2d
function Send() Add

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Suzutomo 0:6a2dcf5cd545 1 //--------------------------------------------------------
Suzutomo 0:6a2dcf5cd545 2 // SPI を使って WS2812B を点灯するためのクラス(ヘッダ)
Suzutomo 0:6a2dcf5cd545 3 // サポートするボード: Nucleo-F401RE, Nucleo-F446RE
Suzutomo 0:6a2dcf5cd545 4 //
Suzutomo 0:6a2dcf5cd545 5 // 2016/11/21, Copyright (c) 2016 MIKAMI, Naoki
Suzutomo 0:6a2dcf5cd545 6 //--------------------------------------------------------
Suzutomo 0:6a2dcf5cd545 7
Suzutomo 0:6a2dcf5cd545 8 #include "mbed.h"
Suzutomo 0:6a2dcf5cd545 9
Suzutomo 0:6a2dcf5cd545 10 #ifndef STM32F4xx_WS2812B_HPP
Suzutomo 0:6a2dcf5cd545 11 #define STM32F4xx_WS2812B_HPP
Suzutomo 0:6a2dcf5cd545 12
Suzutomo 0:6a2dcf5cd545 13 class WS2812B
Suzutomo 0:6a2dcf5cd545 14 {
Suzutomo 0:6a2dcf5cd545 15 public:
Suzutomo 0:6a2dcf5cd545 16 // コンストラクタ
Suzutomo 0:6a2dcf5cd545 17 // inv = true: インバータを介して WS2812B に接続する場合
Suzutomo 0:6a2dcf5cd545 18 // = false: 直接 WS2812B に接続する場合
Suzutomo 3:c0a82b9775e6 19 WS2812B(PinName pin, int num, bool inv = false);
Suzutomo 0:6a2dcf5cd545 20
Suzutomo 0:6a2dcf5cd545 21 virtual ~WS2812B() {}
Suzutomo 0:6a2dcf5cd545 22
Suzutomo 3:c0a82b9775e6 23 void Send(); // LED へ書き込む
Suzutomo 3:c0a82b9775e6 24 void Write(uint32_t x,double brightness = 1.0); // 一つの LED へ書き込む
Suzutomo 3:c0a82b9775e6 25 void Write(int index,uint32_t x,double brightness = 1.0); // k 個の LED へ書き込む
Suzutomo 0:6a2dcf5cd545 26 void Reset() { wait_us(50); }
Suzutomo 0:6a2dcf5cd545 27 void Clear(int k); // k 個の LED を消灯
Suzutomo 3:c0a82b9775e6 28 void Brightness(double brightness);
Suzutomo 0:6a2dcf5cd545 29
Suzutomo 0:6a2dcf5cd545 30 private:
Suzutomo 3:c0a82b9775e6 31 uint32_t *colors;
Suzutomo 3:c0a82b9775e6 32 int bufferSize;
Suzutomo 3:c0a82b9775e6 33 double bright;
Suzutomo 3:c0a82b9775e6 34
Suzutomo 0:6a2dcf5cd545 35 SPI spi_;
Suzutomo 0:6a2dcf5cd545 36 SPI_TypeDef *mySpi_;
Suzutomo 0:6a2dcf5cd545 37
Suzutomo 0:6a2dcf5cd545 38 void (WS2812B::*fp)(uint8_t);
Suzutomo 0:6a2dcf5cd545 39 void SendByte(uint8_t x) { (this->*fp)(x); }
Suzutomo 0:6a2dcf5cd545 40 void Send3Bytes(uint8_t x0, uint8_t x1, uint8_t x2);
Suzutomo 2:b472bd90c6ce 41 void T0HL() { Send3Bytes(0xFF, 0x00, 0x00); } // 0 を送る
Suzutomo 0:6a2dcf5cd545 42 void T1HL() { Send3Bytes(0xFF, 0xFF, 0x00); } // 1 を送る
Suzutomo 0:6a2dcf5cd545 43 void SendByteNorm(uint8_t x); // データをそのまま送る
Suzutomo 0:6a2dcf5cd545 44 void SendByteInv(uint8_t x); // データを反転して送る
Suzutomo 0:6a2dcf5cd545 45
Suzutomo 0:6a2dcf5cd545 46 // コピー・コンストラクタと代入演算子は使用禁止
Suzutomo 0:6a2dcf5cd545 47 WS2812B(const WS2812B&);
Suzutomo 0:6a2dcf5cd545 48 WS2812B& operator=(const WS2812B&);
Suzutomo 0:6a2dcf5cd545 49 };
Suzutomo 0:6a2dcf5cd545 50 #endif