Advertisement
Guest User

Teensy Octo Matrix Sample

a guest
Oct 19th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #define USE_OCTOWS2811
  2. #include <OctoWS2811.h>
  3. #include <FastLED.h>
  4.  
  5. #include <LEDMatrix.h>
  6.  
  7. #define MATRIX_WIDTH 48 // Set this negative if physical led 0 is opposite to where you want logical 0
  8. #define MATRIX_HEIGHT 24 // Set this negative if physical led 0 is opposite to where you want logical 0
  9. #define MATRIX_TYPE HORIZONTAL_ZIGZAG_MATRIX // See top of LEDMatrix.h for matrix wiring types
  10.  
  11. cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;
  12.  
  13.  
  14. void setup()
  15. {
  16. FastLED.addLeds<OCTOWS2811>(leds[0], (MATRIX_HEIGHT / 8) * MATRIX_WIDTH);
  17.  
  18. FastLED.setBrightness(255);
  19. FastLED.clear(true);
  20. delay(500);
  21. FastLED.showColor(CRGB::Red);
  22. delay(500);
  23. FastLED.showColor(CRGB::Lime);
  24. delay(500);
  25. FastLED.showColor(CRGB::Blue);
  26. delay(500);
  27. FastLED.showColor(CRGB::White);
  28. delay(500);
  29. FastLED.clear(true);
  30. }
  31.  
  32.  
  33. void loop()
  34. {
  35. HuePlasma();
  36. FastLED.show();
  37. delay(20);
  38. }
  39.  
  40.  
  41. void HuePlasma()
  42. {
  43. static uint16_t PlasmaTime = 0, PlasmaShift = 0;
  44. #define PLASMA_X_FACTOR 24
  45. #define PLASMA_Y_FACTOR 24
  46.  
  47. int16_t r, h;
  48. int x, y;
  49.  
  50. if (PlasmaShift == 0)
  51. PlasmaShift = (random8(0, 5) * 32) + 64;
  52. for (x = 0; x < MATRIX_WIDTH; x++)
  53. {
  54. for (y = 0; y < MATRIX_HEIGHT; y++)
  55. {
  56. r = sin16(PlasmaTime) / 256;
  57. h = sin16(x * r * PLASMA_X_FACTOR + PlasmaTime) + cos16(y * (-r) * PLASMA_Y_FACTOR + PlasmaTime) + sin16(y * x * (cos16(-PlasmaTime) / 256) / 2);
  58. leds(x, y) = CHSV((h / 256) + 128, 255, 255);
  59. }
  60. }
  61. if ( (PlasmaTime + PlasmaShift) < PlasmaTime )
  62. {
  63. PlasmaTime += PlasmaShift;
  64. PlasmaShift = (random8(0, 5) * 32) + 64;
  65. }
  66. else
  67. PlasmaTime += PlasmaShift;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement