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.
neopixel.h
00001 #ifndef NEOPIXEL_H 00002 #define NEOPIXEL_H 00003 #include "mbed.h" 00004 #include <vector> 00005 00006 /* 00007 // Example 00008 00009 NeoPixelOut npx(D12,6);//出力ピン LEDの個数 00010 00011 int main() { 00012 wait(0.2); // wait for HSE to stabilize 00013 00014 npx.global_scale = 1.0f; // Adjust brightness 明るさを変えるとき以外書かなくていいよ。 00015 npx.normalize = false; // Equalize brightness to make r + g + b = 255 00016 00017 npx.setPixelColor(0,0xff0000); 00018 npx.setPixelColor(1,0xffff00); 00019 npx.setPixelColor(2,0x00ff00); 00020 npx.setPixelColor(3,0x00ffff); 00021 npx.setPixelColor(4,0x0000ff); 00022 npx.setPixelColor(5,0xff00ff); 00023 00024 npx.show(); 00025 00026 while(1); 00027 } 00028 00029 または、 00030 Pixel strip[6]; 00031 strip[0].hex = 0xff0000; 00032 strip[1].hex = 0xffff00; 00033 strip[2].hex = 0x00ff00; 00034 strip[3].hex = 0x00ffff; 00035 strip[4].hex = 0x0000ff; 00036 strip[5].hex = 0xff00ff; 00037 00038 npx.send(strip, 6); 00039 00040 */ 00041 00042 00043 /** 00044 * @brief Struct for easy manipulation of RGB colors. 00045 * 00046 * Set components in the xrgb.r (etc.) and you will get 00047 * the hex in xrgb.num. 00048 */ 00049 union Pixel { 00050 /** Struct for access to individual color components */ 00051 struct __attribute__((packed)) { 00052 uint8_t b; 00053 uint8_t g; 00054 uint8_t r; 00055 uint8_t a; // unused 00056 }; 00057 00058 /** RGB color as a single uint32_t */ 00059 uint32_t hex; 00060 }; 00061 00062 00063 class NeoPixelOut : DigitalOut { 00064 private: 00065 inline void byte(uint32_t b); 00066 int num_pixels_; 00067 Pixel buf_; 00068 vector<Pixel> strip_; 00069 00070 public: 00071 bool normalize; 00072 float global_scale; 00073 00074 NeoPixelOut(PinName pin, int num = 0); 00075 00076 void send(Pixel *colors, uint32_t count, bool flipwait=true);//pixel変数の配列と個数を渡してLEDに送信する。 00077 void changeNum(uint32_t num);//LEDの個数の変更 00078 void setBrightness(float brightness);//0~1 00079 void setPixelColor(uint32_t i,uint8_t b,uint8_t g,uint8_t r);//rgbそれぞれ個別に明るさを設定する。 00080 void setPixelColor(uint32_t i,uint32_t color);//この関数でそれぞれのLEDの明るさを指定し 00081 void show(bool flipwait=true);//この関数を呼び出してLEDに信号を送ってください。 00082 void off(bool flag = true);//LEDを消す。flagは、送信するかしないか。デフォルトでする。 00083 uint32_t color(uint8_t b,uint8_t g,uint8_t r); 00084 int numPixels();//LEDの個数を返す。クラス宣言時に指定した数と同じ。 00085 00086 /** Wait long enough to make the colors show up */ 00087 void flip(void); 00088 }; 00089 00090 00091 #endif /* NEOPIXEL_H */
Generated on Sat Oct 15 2022 07:52:33 by
1.7.2