blip_rainbow for Mbed OS 5.x

Dependencies:   PixelArray

Committer:
cyliang
Date:
Thu Feb 06 07:10:24 2020 +0000
Revision:
4:ad1c22b1de40
Parent:
3:2d84c8262139
Port blip_rainbow to Mbed OS 5 and support M487 platform

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pighixxx 3:2d84c8262139 1 // miniblip led matrix demo
pighixxx 3:2d84c8262139 2
JacobBramley 0:60499ad28ea9 3 #include "mbed.h"
JacobBramley 1:ca76237d2965 4 #include "neopixel.h"
JacobBramley 0:60499ad28ea9 5
pighixxx 3:2d84c8262139 6 // Matrix led output pin
cyliang 4:ad1c22b1de40 7 #if defined(TARGET_NUMAKER_IOT_M487)
cyliang 4:ad1c22b1de40 8 #define DATA_PIN PA_8
cyliang 4:ad1c22b1de40 9 #else
cyliang 4:ad1c22b1de40 10 #define DATA_PIN D9
cyliang 4:ad1c22b1de40 11 #endif
JacobBramley 0:60499ad28ea9 12
JacobBramley 1:ca76237d2965 13 void generate(neopixel::Pixel * out, uint32_t index, uintptr_t extra)
JacobBramley 1:ca76237d2965 14 {
JacobBramley 1:ca76237d2965 15 uint32_t brightness = (index + extra) >> 3;
JacobBramley 1:ca76237d2965 16 out->red = ((index + extra) & 0x1) ? brightness : 0;
JacobBramley 1:ca76237d2965 17 out->green = ((index + extra) & 0x2) ? brightness : 0;
JacobBramley 1:ca76237d2965 18 out->blue = ((index + extra) & 0x4) ? brightness : 0;
JacobBramley 0:60499ad28ea9 19 }
JacobBramley 0:60499ad28ea9 20
JacobBramley 1:ca76237d2965 21 int main()
JacobBramley 1:ca76237d2965 22 {
pighixxx 3:2d84c8262139 23 // Turn off miniblip buzzer
cyliang 4:ad1c22b1de40 24 PwmOut speaker(D2);
pighixxx 3:2d84c8262139 25 speaker=0.0;
JacobBramley 1:ca76237d2965 26 // Create a temporary DigitalIn so we can configure the pull-down resistor.
JacobBramley 1:ca76237d2965 27 DigitalIn(DATA_PIN, PullDown);
JacobBramley 1:ca76237d2965 28
cyliang 4:ad1c22b1de40 29 printf("Start LED pixel-array demo...\r\n");
JacobBramley 1:ca76237d2965 30 // The pixel array control class.
JacobBramley 1:ca76237d2965 31 neopixel::PixelArray array(DATA_PIN);
JacobBramley 1:ca76237d2965 32
JacobBramley 1:ca76237d2965 33 uint32_t offset = 0;
pighixxx 3:2d84c8262139 34 uint32_t i = 1;
JacobBramley 1:ca76237d2965 35 while (1) {
pighixxx 3:2d84c8262139 36 array.update(generate, 64, offset++);
pighixxx 3:2d84c8262139 37
pighixxx 3:2d84c8262139 38 //Play Sound
pighixxx 3:2d84c8262139 39 float note=500+(i*100);
pighixxx 3:2d84c8262139 40 //speaker.period(1.0/note);
pighixxx 3:2d84c8262139 41 //speaker = float(i)/50.0;
pighixxx 3:2d84c8262139 42
pighixxx 3:2d84c8262139 43 i++;
pighixxx 3:2d84c8262139 44 if (i>10) i=1;
pighixxx 3:2d84c8262139 45 // Rainbow delay
pighixxx 3:2d84c8262139 46 wait_ms(100);
JacobBramley 0:60499ad28ea9 47 }
JacobBramley 0:60499ad28ea9 48 }