![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Simple 8x8 LED Matrix controller which interfaces with a Processing GUI over serial to display sketches
Dependencies: Multi_WS2811 mbed
Fork of Multi_WS2811_test by
main.cpp@20:b9d76e567637, 2013-12-21 (annotated)
- Committer:
- bikeNomad
- Date:
- Sat Dec 21 04:32:21 2013 +0000
- Revision:
- 20:b9d76e567637
- Parent:
- 19:600deef36348
- Child:
- 21:4541da183397
still trying to get DMA to work
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bikeNomad | 17:b4e9d8f4baa9 | 1 | #include "mbed.h" |
bikeNomad | 18:d98353e8c61c | 2 | #include "WS2811.h" |
bikeNomad | 19:600deef36348 | 3 | #include "Colors.h" |
bikeNomad | 17:b4e9d8f4baa9 | 4 | |
bikeNomad | 20:b9d76e567637 | 5 | const unsigned nLEDs = 60*4; |
bikeNomad | 20:b9d76e567637 | 6 | |
bikeNomad | 20:b9d76e567637 | 7 | const PinName dataOutput = PTD2; |
bikeNomad | 20:b9d76e567637 | 8 | const PinName sckOutput = PTD1; |
bikeNomad | 20:b9d76e567637 | 9 | SPI_Type *spiPort = SPI0; |
bikeNomad | 20:b9d76e567637 | 10 | |
bikeNomad | 20:b9d76e567637 | 11 | DigitalOut debugOut(PTD3); |
bikeNomad | 20:b9d76e567637 | 12 | Serial pc(USBTX, USBRX); |
bikeNomad | 20:b9d76e567637 | 13 | |
bikeNomad | 20:b9d76e567637 | 14 | // @brief sets different colors in each of the LEDs of a strip |
bikeNomad | 20:b9d76e567637 | 15 | // @param strip the light strip |
bikeNomad | 20:b9d76e567637 | 16 | // @param sat saturation, 0.0 - 1.0 |
bikeNomad | 20:b9d76e567637 | 17 | // @param brite brightness, 0.0 - 1.0 |
bikeNomad | 20:b9d76e567637 | 18 | // @param hueShift shift, 0.0 - 1.0 is equivalent to 0 - 360 degrees |
bikeNomad | 20:b9d76e567637 | 19 | void showRainbow(WS2811 &strip, float sat, float brite, float hueShift) |
bikeNomad | 20:b9d76e567637 | 20 | { |
bikeNomad | 20:b9d76e567637 | 21 | unsigned nLEDs = strip.numPixels(); |
bikeNomad | 20:b9d76e567637 | 22 | for (unsigned i = 0; i < nLEDs; i++) { |
bikeNomad | 20:b9d76e567637 | 23 | uint8_t r, g, b; |
bikeNomad | 20:b9d76e567637 | 24 | float hue = ((float)i / (float)nLEDs) + hueShift; |
bikeNomad | 20:b9d76e567637 | 25 | HSBtoRGB(hue, sat, brite, &r, &g, &b); |
bikeNomad | 20:b9d76e567637 | 26 | strip.setPixelColor(i, LedStrip::Color(r, g, b)); |
bikeNomad | 20:b9d76e567637 | 27 | } |
bikeNomad | 20:b9d76e567637 | 28 | strip.begin(); |
bikeNomad | 20:b9d76e567637 | 29 | } |
bikeNomad | 20:b9d76e567637 | 30 | void showTestPattern(WS2811 &strip) |
bikeNomad | 20:b9d76e567637 | 31 | { |
bikeNomad | 20:b9d76e567637 | 32 | unsigned nLEDs = strip.numPixels(); |
bikeNomad | 20:b9d76e567637 | 33 | for (unsigned i = 0; i < nLEDs; i++) { |
bikeNomad | 20:b9d76e567637 | 34 | strip.setPixelColor(i, LedStrip::Color(0xff,0,0x55)); |
bikeNomad | 20:b9d76e567637 | 35 | } |
bikeNomad | 20:b9d76e567637 | 36 | strip.show(); |
bikeNomad | 20:b9d76e567637 | 37 | } |
bikeNomad | 20:b9d76e567637 | 38 | void dump_spi_settings(SPI_Type const *spi) |
bikeNomad | 20:b9d76e567637 | 39 | { |
bikeNomad | 20:b9d76e567637 | 40 | pc.printf("SPI C1=%#02x, C2=%#02x, BR=%d, S=%#02x, D=%#02x, M=%02x\r\n", spi->C1, spi->C2, spi->BR, spi->S, spi->D, spi->M); |
bikeNomad | 20:b9d76e567637 | 41 | pc.printf("DMA DSR_BCR=%#08lx, SAR=%p, DAR=%p, DCR=%#08lx\r\n", |
bikeNomad | 20:b9d76e567637 | 42 | (unsigned long)DMA0->DMA[0].DSR_BCR, |
bikeNomad | 20:b9d76e567637 | 43 | DMA0->DMA[0].SAR, |
bikeNomad | 20:b9d76e567637 | 44 | DMA0->DMA[0].DAR, |
bikeNomad | 20:b9d76e567637 | 45 | DMA0->DMA[0].DCR); |
bikeNomad | 20:b9d76e567637 | 46 | } |
bikeNomad | 20:b9d76e567637 | 47 | |
bikeNomad | 17:b4e9d8f4baa9 | 48 | int main(void) |
bikeNomad | 17:b4e9d8f4baa9 | 49 | { |
bikeNomad | 20:b9d76e567637 | 50 | pc.baud(115200); |
bikeNomad | 20:b9d76e567637 | 51 | pc.printf("LEDs: %d\r\n", nLEDs); |
bikeNomad | 20:b9d76e567637 | 52 | debugOut = 0; |
bikeNomad | 19:600deef36348 | 53 | |
bikeNomad | 20:b9d76e567637 | 54 | // NLEDs MOSI SCK |
bikeNomad | 20:b9d76e567637 | 55 | WS2811 lightStrip(nLEDs, spiPort, dataOutput, sckOutput); |
bikeNomad | 20:b9d76e567637 | 56 | |
bikeNomad | 20:b9d76e567637 | 57 | lightStrip.begin(); |
bikeNomad | 20:b9d76e567637 | 58 | dump_spi_settings(spiPort); |
bikeNomad | 19:600deef36348 | 59 | |
bikeNomad | 20:b9d76e567637 | 60 | // float sat = 1.0; |
bikeNomad | 20:b9d76e567637 | 61 | // float brite = 0.25; |
bikeNomad | 20:b9d76e567637 | 62 | // float hueShift = 0.0; |
bikeNomad | 20:b9d76e567637 | 63 | // float hueShiftIncrement = 1.0 / (360.0 / 30.0); |
bikeNomad | 20:b9d76e567637 | 64 | for (;;) { |
bikeNomad | 20:b9d76e567637 | 65 | // debugOut = 1; |
bikeNomad | 20:b9d76e567637 | 66 | // showRainbow(lightStrip, sat, brite, hueShift); |
bikeNomad | 20:b9d76e567637 | 67 | showTestPattern(lightStrip); |
bikeNomad | 20:b9d76e567637 | 68 | |
bikeNomad | 20:b9d76e567637 | 69 | // debugOut = 0; |
bikeNomad | 20:b9d76e567637 | 70 | // hueShift += hueShiftIncrement; |
bikeNomad | 20:b9d76e567637 | 71 | } |
bikeNomad | 17:b4e9d8f4baa9 | 72 | } |