diff --git a/Feather-M4-Express_NeoTrellis_Music-Maker-FeatherWing-w-Amp.ino b/Feather-M4-Express_NeoTrellis_Music-Maker-FeatherWing-w-Amp.ino new file mode 100644 index 0000000..3176945 --- /dev/null +++ b/Feather-M4-Express_NeoTrellis_Music-Maker-FeatherWing-w-Amp.ino @@ -0,0 +1,243 @@ +// include NeoTrellis library +#include +// include SPI, MP3 and SD libraries +#include +#include +#include + +// Set up NeoTrellis +Adafruit_NeoTrellis trellis; +#define INT_PIN 11 // Interrupt pin needs to be unused by MusicMaker + +#define MAX_RIPPLES 16 +#define FALLOFF_TIME 30 +#define FALLOFF (0xFF/FALLOFF_TIME) +#define NUM_POINTS 8 +#define RIPPLE_RATE .4 +#define MATRIX_POINT(x,y) ((y)*4+(x)) + +// Set up MusicMaker +#define VS1053_RESET -1 // VS1053 reset pin (not used!) +#define VS1053_CS 6 // VS1053 chip select pin (output) +#define VS1053_DCS 10 // VS1053 Data/command select pin (output) +#define CARDCS 5 // Card chip select pin +#define VS1053_DREQ 9 // VS1053 Data request, ideally an Interrupt pin + +uint32_t colors[] = { + 0xFF0000, 0x00FF00, 0x0000FF, + 0xFF00FF, 0x00FFFF, 0xFFFFFF +}; + +union color { + struct { + uint8_t blue:8; + uint8_t green:8; + uint8_t red:8; + } bit; + uint32_t reg; +}; + +color matrix[4][4]; + +struct point { + float x; + float y; +}; + +struct ripple { + int8_t center; + uint32_t t; + color c; + point points[NUM_POINTS]; +}; + +static struct ripple ripples[MAX_RIPPLES]; + +//define a callback for key presses +TrellisCallback blink(keyEvent evt){ + + for(int i=0; i -1){ + update = true; + + //push all points out from the center + point *p = ripples[i].points; + + p[0].x += RIPPLE_RATE; + + p[1].x += RIPPLE_RATE/2; + p[1].y += RIPPLE_RATE/2; + + p[2].y += RIPPLE_RATE; + + p[3].x -= RIPPLE_RATE/2; + p[3].y += RIPPLE_RATE/2; + + p[4].x -= RIPPLE_RATE; + + p[5].x -= RIPPLE_RATE/2; + p[5].y -= RIPPLE_RATE/2; + + p[6].y -= RIPPLE_RATE; + + p[7].x += RIPPLE_RATE/2; + p[7].y -= RIPPLE_RATE/2; + + for(int j=0; j= 0 && y < 4 && y >= 0){ + byte red = min(255, matrix[x][y].bit.red + ripples[i].c.bit.red); + byte green = min(255, matrix[x][y].bit.green + ripples[i].c.bit.green); + byte blue = min(255, matrix[x][y].bit.blue + ripples[i].c.bit.blue); + matrix[x][y].bit.red = red; + matrix[x][y].bit.green = green; + matrix[x][y].bit.blue = blue; + } + } + + + ripples[i].t++; + if(ripples[i].t >= FALLOFF_TIME) ripples[i].center = -1; + } + } + + if(update){ + for(int x=0; x<4; x++){ + for(int y=0; y<4; y++) + trellis.pixels.setPixelColor(MATRIX_POINT(x,y), matrix[x][y].reg); + } + + trellis.pixels.show(); + } +} \ No newline at end of file