blip_rainbow for Mbed OS 5.x

Dependencies:   PixelArray

main.cpp

Committer:
cyliang
Date:
2020-02-06
Revision:
4:ad1c22b1de40
Parent:
3:2d84c8262139

File content as of revision 4:ad1c22b1de40:

// miniblip led matrix demo

#include "mbed.h"
#include "neopixel.h"

// Matrix led output pin
#if defined(TARGET_NUMAKER_IOT_M487)
#define DATA_PIN PA_8
#else
#define DATA_PIN D9
#endif

void generate(neopixel::Pixel * out, uint32_t index, uintptr_t extra)
{
    uint32_t brightness = (index + extra) >> 3;
    out->red   = ((index + extra) & 0x1) ? brightness : 0;
    out->green = ((index + extra) & 0x2) ? brightness : 0;
    out->blue  = ((index + extra) & 0x4) ? brightness : 0;
}

int main()
{
    // Turn off miniblip buzzer
    PwmOut speaker(D2);
    speaker=0.0;
    // Create a temporary DigitalIn so we can configure the pull-down resistor.
    DigitalIn(DATA_PIN, PullDown);

    printf("Start LED pixel-array demo...\r\n");
    // The pixel array control class.
    neopixel::PixelArray array(DATA_PIN);

    uint32_t offset = 0;
    uint32_t i = 1;
    while (1) {
        array.update(generate, 64, offset++);
        
        //Play Sound
        float note=500+(i*100);
        //speaker.period(1.0/note);           
        //speaker = float(i)/50.0;
        
        i++;
        if (i>10) i=1;
        // Rainbow delay
        wait_ms(100);
    }
}