![](/media/cache/profiles/P1030212_resized.JPG.50x50_q85.jpg)
明石高専ロボ研 mbedライブラリ
Dependents: MDD_L432KC USB2RS485 pathtracking odometry ... more
Diff: neopixel.cpp
- Revision:
- 7:4ad54efe2fdd
- Parent:
- 5:a7894e6982ea
- Child:
- 8:82727add54ce
diff -r 678c6b604ac7 -r 4ad54efe2fdd neopixel.cpp --- a/neopixel.cpp Thu Nov 12 16:44:10 2020 +0000 +++ b/neopixel.cpp Sun Dec 06 08:09:01 2020 +0000 @@ -1,24 +1,28 @@ #include "mbed.h" #include "neopixel.h" -const int wait_time[4][2] = { - {6, 9}, - {2, 5}, - {2, 4}, - {5, 9} -}; +#if defined(TARGET_NUCLEO_L432KC) + +#define PIXEL_WAIT_1_ (6) +#define PIXEL_WAIT_2_ (2) +#define PIXEL_WAIT_3_ (2) +#define PIXEL_WAIT_4_ (5) + +#elif defined(TARGET_NUCLEO_F446RE) + +#define PIXEL_WAIT_1_ (9) +#define PIXEL_WAIT_2_ (5) +#define PIXEL_WAIT_3_ (4) +#define PIXEL_WAIT_4_ (9) + +#else +#error "This board is not supported" +#endif NeoPixelOut::NeoPixelOut(PinName pin, int num) : DigitalOut(pin) { normalize = false; global_scale = 1.0f; - #if defined(TARGET_NUCLEO_L432KC) - board_ = 0; - #elif defined(TARGET_NUCLEO_F446RE) - board_ = 1; - #else - #error "This board is not supported" - #endif num_pixels_ = num; strip_.resize(num); } @@ -32,17 +36,17 @@ // duty cycle determines bit value if (byte & 0x80) { // one - for(int j = 0; j < wait_time[0][board_]; j++) asm("NOP");//6 9 + for(int j = 0; j < PIXEL_WAIT_1_; j++) asm("NOP");//6 9 gpio_write(&gpio, 0); - for(int j = 0; j < wait_time[1][board_]; j++) asm("NOP");//2 5 + for(int j = 0; j < PIXEL_WAIT_2_; j++) asm("NOP");//2 5 } else { // zero - for(int j = 0; j < wait_time[2][board_]; j++) asm("NOP");//2 4 + for(int j = 0; j < PIXEL_WAIT_3_; j++) asm("NOP");//2 4 gpio_write(&gpio, 0); - for(int j = 0; j < wait_time[3][board_]; j++) asm("NOP");//5 9 + for(int j = 0; j < PIXEL_WAIT_4_; j++) asm("NOP");//5 9 } byte = byte << 1; // shift to next bit @@ -62,8 +66,7 @@ __disable_irq(); float fr,fg,fb; - int count = strip_.size(); - for (int i = 0; i < count; i++) { + for (int i = 0; i < num_pixels_; i++) { fr = strip_[i].r; fg = strip_[i].g; fb = strip_[i].b;