LPC812MAXでWS2812Bを光らせる。(mbed2リビジョン144)



x mbed2リビジョン144
x リビジョンを変更できる人むけ


目的
GPIOのテスト

構成
マイコン内蔵ＲＧＢＬＥＤ　ＷＳ２８１２Ｂ　（２個入）
[WS2812B(V5)]
通販コード　I-07915
発売日　2014/05/27
メーカーカテゴリ　Worldsemi Co.,Limited (ワールドセミ)



![o_con751.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/ebfd11fa-ae3b-7c4d-e758-b4b51d5eb0bd.jpeg)




```c++



//WB2812B_test1_812_1

#include "mbed.h"


DigitalOut myled(P0_6);

#define io_def 0x80

//             654321009876543210
//#define on1    0b0000000010000000
//#define off1   0b0000000000000000


//             654321009876543210
#define on1    0b0000000001000000
#define off1   0b0000000000000000


int l[90]; //max30 led

void bit_on1();
void bit_off1();

//             12345678   12345678   12345678   12345678
int b8[8] = {0b10000000,0b01000000,0b00100000,0b00010000,
             0b00001000,0b00000100,0b00000010,0b00000001,
            };

int ws_led(int num1)
{
    int on_off;

    __disable_irq(); // disable interrupt
    //__enable_irq(); // enable interrupt



    for(int ii=0; ii<num1; ii++) {

        //8ビット分送る
        for(int jj=0; jj<8; jj++) {

            on_off = l[ii] & b8[jj];

            if( on_off == 0 ) {
                //ビットが0
                bit_off1();
            } else {
                //ビットが1
                bit_on1();
            }//endif

        }//for 8bit


    }//for max30byt

    //__disable_irq(); // disable interrupt
    __enable_irq(); // enable interrupt

    return(0);
}

//メイン関数
int main()
{





    while(1){

       // l[3*0+0] = 31;
       // l[3*0+1] = 32;
       // l[3*0+2] = 33;

        l[3*0+0] = 10;
        l[3*0+1] = 10;
        l[3*0+2] = 10;


        //
        l[3*1+0] = 15;
        l[3*1+1] = 15;
        l[3*1+2] = 15;
        //
        //l[3*2+0] = 10;
        //l[3*2+1] = 10;
        //l[3*2+2] = 32;

        //for(int ii=0;ii<9;ii++){
        //    l[ii] = rand()%52;
        //}//for

        //ws2812bへデータを送る
        ws_led(6);

        //1秒待つ
        wait_ms(100);

    } //while

} //main

// 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3
void bit_off1()
{
    //0.3us 800khz

        LPC_GPIO_PORT->PIN0 = on1;

        __NOP();
        __NOP();
        __NOP();
        
        LPC_GPIO_PORT->PIN0 = off1;
        
        __NOP();
        __NOP();

        //LPC_GPIO_PORT->PIN0 = off1;

        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();

        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();

}//bit_off1


// 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
void bit_on1()
{
    //1us 800khz

        LPC_GPIO_PORT->PIN0 = on1;

        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();

        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();

        LPC_GPIO_PORT->PIN0 = off1;

        __NOP();
        __NOP();
        __NOP();
        __NOP();
        __NOP();

}//bit_on1





```



![o_con833.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/32fd9f52-8dee-a1d4-8980-41b5bb12f294.jpeg)


-26-