LPC1114でWS2812Bを光らせる。 (ハードは、ichigojam)


x まだ、ためしていないけど動くはず6/8(先行アップしました。動かなかったみたいです)
x よくわからない実行エラーが出たので修正した。6/10
x 結果、ws2812bは、光った6/10(初期化と終了処理の追加)6/10

目的
GPIOのテスト



![gpio_ws2812b_1114.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/840352/75709c33-1f97-8168-c0d5-fe7e6f21e959.jpeg)





初期化と終了処理を追加したコード


```c++


//#include "mbed.h"

//DigitalOut myled(dp6);
//
//int main() {
//   while(1) {
//        myled = 1;
//        wait(0.2);
//        myled = 0;
//        wait(0.2);
//    }
//}


#include "mbed.h"

// 4.380Mhz

DigitalOut myled(dp6);

#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

    //GPIO bkup
    //int g_bk  = GPIOA->ODR;


    for(int ii=0;ii<num1;ii++){
        //pc.printf("  -%d\t%d\r\n",ii,l[ii]); //303
        
        //8ビット分送る
        for(int jj=0;jj<8;jj++){
            //pc.printf("  -%d\r\n",jj); //303
            
            on_off = l[ii] & b8[jj];
        
            if( on_off == 0 ){
                //ビットが0
                //pc.printf("0"); //303
                bit_off1();
            } else {
                //ビットが1 
                //pc.printf("1"); //303
                bit_on1();
            }//endif
        
        }//for 8bit
        
        
    }//for max30byt

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

    //GPIO bkup
    //GPIOA->ODR = g_bk;

    return(0);
}


//メイン
int main() {

    //リセットを送ろ為のウエート
    LPC_GPIO0->DATA = off1;
    wait_ms(1);
    
    l[0] = 31;
    l[1] = 32;
    l[2] = 33;

    ws_led(3);

    //無限ループ
    while(1){}

//   while(1) {
//        //myled = 1;
//        //LPC_GPIO0->DATA = on1;
//        //bit_off1();
//        ws_led(3);
//        wait(0.2);
//        //myled = 0;
//        //LPC_GPIO0->DATA = off1;
//        //bit_on1();
//        ws_led(3);
//        wait(0.2);
//    }

    
    //pc.printf("\r\n303\r\n"); //303

} //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_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;

        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
}//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_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;

        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
}//bit_on1




```





よくわからない実行エラーが出た　動かないコード(参考)



```c++


#include "mbed.h"

// 4.380Mhz

DigitalOut myled(dp6);

#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

    //GPIO bkup
    //int g_bk  = GPIOA->ODR;


    for(int ii=0;ii<num1;ii++){
        //pc.printf("  -%d\t%d\r\n",ii,l[ii]); //303
        
        //8ビット分送る
        for(int jj=0;jj<8;jj++){
            //pc.printf("  -%d\r\n",jj); //303
            
            on_off = l[ii] & b8[jj];
        
            if( on_off == 0 ){
                //ビットが0
                //pc.printf("0"); //303
                bit_off1();
            } else {
                //ビットが1 
                //pc.printf("1"); //303
                bit_on1();
            }//endif
        
        }//for 8bit
        
        
    }//for max30byt

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

    //GPIO bkup
    //GPIOA->ODR = g_bk;

    return(0);
}

//メイン
int main() {
    
    //pc.printf("\r\n303\r\n"); //303

    l[0] = 31;
    l[1] = 32;
    l[2] = 33;

    ws_led(3);

} //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_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;

        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
}//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_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;
        LPC_GPIO0->DATA = on1;

        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
        LPC_GPIO0->DATA = off1;
}//bit_on1



```