my new gear...

Dependencies:   mbed

Committer:
yootee
Date:
Sun Mar 27 04:51:16 2022 +0000
Revision:
3:a9b4b2565a23
my new gear...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yootee 3:a9b4b2565a23 1 #ifndef NEOPIXEL_H
yootee 3:a9b4b2565a23 2 #define NEOPIXEL_H
yootee 3:a9b4b2565a23 3 #include "mbed.h"
yootee 3:a9b4b2565a23 4 #include <vector>
yootee 3:a9b4b2565a23 5
yootee 3:a9b4b2565a23 6 /*
yootee 3:a9b4b2565a23 7 // Example
yootee 3:a9b4b2565a23 8
yootee 3:a9b4b2565a23 9 NeoPixelOut npx(D12,6);//出力ピン LEDの個数
yootee 3:a9b4b2565a23 10
yootee 3:a9b4b2565a23 11 int main() {
yootee 3:a9b4b2565a23 12 wait(0.2); // wait for HSE to stabilize
yootee 3:a9b4b2565a23 13
yootee 3:a9b4b2565a23 14 npx.global_scale = 1.0f; // Adjust brightness 明るさを変えるとき以外書かなくていいよ。
yootee 3:a9b4b2565a23 15 npx.normalize = false; // Equalize brightness to make r + g + b = 255
yootee 3:a9b4b2565a23 16
yootee 3:a9b4b2565a23 17 npx.setPixelColor(0,0xff0000);
yootee 3:a9b4b2565a23 18 npx.setPixelColor(1,0xffff00);
yootee 3:a9b4b2565a23 19 npx.setPixelColor(2,0x00ff00);
yootee 3:a9b4b2565a23 20 npx.setPixelColor(3,0x00ffff);
yootee 3:a9b4b2565a23 21 npx.setPixelColor(4,0x0000ff);
yootee 3:a9b4b2565a23 22 npx.setPixelColor(5,0xff00ff);
yootee 3:a9b4b2565a23 23
yootee 3:a9b4b2565a23 24 npx.show();
yootee 3:a9b4b2565a23 25
yootee 3:a9b4b2565a23 26 while(1);
yootee 3:a9b4b2565a23 27 }
yootee 3:a9b4b2565a23 28
yootee 3:a9b4b2565a23 29 または、
yootee 3:a9b4b2565a23 30 Pixel strip[6];
yootee 3:a9b4b2565a23 31 strip[0].hex = 0xff0000;
yootee 3:a9b4b2565a23 32 strip[1].hex = 0xffff00;
yootee 3:a9b4b2565a23 33 strip[2].hex = 0x00ff00;
yootee 3:a9b4b2565a23 34 strip[3].hex = 0x00ffff;
yootee 3:a9b4b2565a23 35 strip[4].hex = 0x0000ff;
yootee 3:a9b4b2565a23 36 strip[5].hex = 0xff00ff;
yootee 3:a9b4b2565a23 37
yootee 3:a9b4b2565a23 38 npx.send(strip, 6);
yootee 3:a9b4b2565a23 39
yootee 3:a9b4b2565a23 40 */
yootee 3:a9b4b2565a23 41
yootee 3:a9b4b2565a23 42
yootee 3:a9b4b2565a23 43 /**
yootee 3:a9b4b2565a23 44 * @brief Struct for easy manipulation of RGB colors.
yootee 3:a9b4b2565a23 45 *
yootee 3:a9b4b2565a23 46 * Set components in the xrgb.r (etc.) and you will get
yootee 3:a9b4b2565a23 47 * the hex in xrgb.num.
yootee 3:a9b4b2565a23 48 */
yootee 3:a9b4b2565a23 49 union Pixel {
yootee 3:a9b4b2565a23 50 /** Struct for access to individual color components */
yootee 3:a9b4b2565a23 51 struct __attribute__((packed)) {
yootee 3:a9b4b2565a23 52 uint8_t b;
yootee 3:a9b4b2565a23 53 uint8_t g;
yootee 3:a9b4b2565a23 54 uint8_t r;
yootee 3:a9b4b2565a23 55 uint8_t a; // unused
yootee 3:a9b4b2565a23 56 };
yootee 3:a9b4b2565a23 57
yootee 3:a9b4b2565a23 58 /** RGB color as a single uint32_t */
yootee 3:a9b4b2565a23 59 uint32_t hex;
yootee 3:a9b4b2565a23 60 };
yootee 3:a9b4b2565a23 61
yootee 3:a9b4b2565a23 62
yootee 3:a9b4b2565a23 63 class NeoPixelOut : DigitalOut {
yootee 3:a9b4b2565a23 64 private:
yootee 3:a9b4b2565a23 65 inline void byte(uint32_t b);
yootee 3:a9b4b2565a23 66 int num_pixels_;
yootee 3:a9b4b2565a23 67 Pixel buf_;
yootee 3:a9b4b2565a23 68 vector<Pixel> strip_;
yootee 3:a9b4b2565a23 69
yootee 3:a9b4b2565a23 70 public:
yootee 3:a9b4b2565a23 71 bool normalize;
yootee 3:a9b4b2565a23 72 float global_scale;
yootee 3:a9b4b2565a23 73
yootee 3:a9b4b2565a23 74 NeoPixelOut(PinName pin, int num = 0);
yootee 3:a9b4b2565a23 75
yootee 3:a9b4b2565a23 76 void send(Pixel *colors, uint32_t count, bool flipwait=true);//pixel変数の配列と個数を渡してLEDに送信する。
yootee 3:a9b4b2565a23 77 void changeNum(uint32_t num);//LEDの個数の変更
yootee 3:a9b4b2565a23 78 void setBrightness(float brightness);//0~1
yootee 3:a9b4b2565a23 79 void setPixelColor(uint32_t i,uint8_t b,uint8_t g,uint8_t r);//rgbそれぞれ個別に明るさを設定する。
yootee 3:a9b4b2565a23 80 void setPixelColor(uint32_t i,uint32_t color);//この関数でそれぞれのLEDの明るさを指定し
yootee 3:a9b4b2565a23 81 void show(bool flipwait=true);//この関数を呼び出してLEDに信号を送ってください。
yootee 3:a9b4b2565a23 82 void off(bool flag = true);//LEDを消す。flagは、送信するかしないか。デフォルトでする。
yootee 3:a9b4b2565a23 83 uint32_t color(uint8_t b,uint8_t g,uint8_t r);
yootee 3:a9b4b2565a23 84 int numPixels();//LEDの個数を返す。クラス宣言時に指定した数と同じ。
yootee 3:a9b4b2565a23 85
yootee 3:a9b4b2565a23 86 /** Wait long enough to make the colors show up */
yootee 3:a9b4b2565a23 87 void flip(void);
yootee 3:a9b4b2565a23 88 };
yootee 3:a9b4b2565a23 89
yootee 3:a9b4b2565a23 90
yootee 3:a9b4b2565a23 91 #endif /* NEOPIXEL_H */