Guest User

Fast_SPI LED Matrix

a guest
Nov 18th, 2013
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. //Here is a great way to learn the basics of programming a LED array comprised of digital strips
  2. //You can modify the definitions to equal the size of your matrix
  3. //Much thanks to the Fast_SPI Google+ Community for the help in creating this code
  4.  
  5. #include "FastSPI_LED2.h"
  6. #define NUM_LEDS 90
  7. #define HorizontalTOTAL 10
  8. #define VerticalTOTAL 9
  9. struct CRGB leds[NUM_LEDS];
  10.  
  11. byte sinwave[9][10]={
  12. { 0,0,0,0,0,0,0,0,0,0 } ,
  13. { 0,0,0,0,255,255,0,0,0,0 } ,
  14. { 0,0,0,255,180,180,255,0,0,0 } ,
  15. { 0,0,255,180,100,100,180,255,0,0 } ,
  16. { 0,255,180,100,30,30,100,180,255,0 } ,
  17. { 255,180,100,30,0,0,30,100,180,255 } ,
  18. { 180,100,30,0,0,0,0,30,100,180 } ,
  19. { 100,30,0,0,0,0,0,0,30,100 } ,
  20. { 30,0,0,0,0,0,0,0,0,30 }};
  21.  
  22. byte lines[9][10]={
  23. { 255,140,85,15,0,0,0,0,0,0 } ,
  24. { 255,140,85,15,0,0,0,0,0,0 } ,
  25. { 255,140,85,15,0,0,0,0,0,0 } ,
  26. { 255,140,85,15,0,0,0,0,0,0 } ,
  27. { 255,140,85,15,0,0,0,0,0,0 } ,
  28. { 255,140,85,15,0,0,0,0,0,0 } ,
  29. { 255,140,85,15,0,0,0,0,0,0 } ,
  30. { 255,140,85,15,0,0,0,0,0,0 } ,
  31. { 255,140,85,15,0,0,0,0,0,0 }};
  32.  
  33. byte blank[9][10]={
  34. { 0,0,0,0,0,0,0,0,0,0 } ,
  35. { 0,0,0,0,0,0,0,0,0,0 } ,
  36. { 0,0,0,0,0,0,0,0,0,0 } ,
  37. { 0,0,0,0,0,0,0,0,0,0 } ,
  38. { 0,0,0,0,0,0,0,0,0,0 } ,
  39. { 0,0,0,0,0,0,0,0,0,0 } ,
  40. { 0,0,0,0,0,0,0,0,0,0 } ,
  41. { 0,0,0,0,0,0,0,0,0,0 } ,
  42. { 0,0,0,0,0,0,0,0,0,0 }};
  43.  
  44. byte Xshift = 0;
  45. byte Yshift = 0;
  46. byte pixel;
  47. byte LEDIndex;
  48. byte countDelay = 0;
  49. byte Speed = 3;
  50. double colorChange = 0.19;
  51. double color = 0.00;
  52. boolean colorDirection = true;
  53. byte sat;
  54.  
  55. void setup(){
  56. // sanity check delay - allows reprogramming if accidently blowing power w/leds
  57. delay(2000);
  58. // For safety (to prevent too high of a power draw)
  59. LEDS.setBrightness(200);
  60. // Initialize your strips
  61. LEDS.addLeds<UCS1903, 4, RBG>(leds, NUM_LEDS); //my strips from china were wired R, B, G
  62. // LEDS.addLeds<WS2811, 13>(leds, NUM_LEDS);
  63. // LEDS.addLeds<TM1809, 13>(leds, NUM_LEDS);
  64. // LEDS.addLeds<TM1803, 13>(leds, NUM_LEDS);
  65. // LEDS.addLeds<P9813>(leds, NUM_LEDS);
  66. // LEDS.addLeds<LPD8806>(leds, NUM_LEDS);
  67. // LEDS.addLeds<WS2801>(leds, NUM_LEDS);
  68. // LEDS.addLeds<SM16716>(leds, NUM_LEDS);
  69. // LEDS.addLeds<WS2811, 11>(leds, NUM_LEDS);
  70. // Put ws2801 strip on the hardware SPI pins with a BGR ordering of rgb and limited to a 1Mhz data rate
  71. // LEDS.addLeds<WS2801, 11, 13, BGR, DATA_RATE_MHZ(1)>(leds, NUM_LEDS);
  72. // LEDS.addLeds<LPD8806, 10, 11>(leds, NUM_LEDS);
  73. // LEDS.addLeds<WS2811, 13, BRG>(leds, NUM_LEDS);
  74. // LEDS.addLeds<LPD8806, BGR>(leds, NUM_LEDS);
  75. }
  76.  
  77. void loop() {
  78. if (++countDelay > Speed){
  79. countDelay = 0;
  80. if (++Xshift >= HorizontalTOTAL)
  81. Xshift = 0;}
  82. memset(leds, 0, NUM_LEDS * 3);
  83. color = color + colorChange;
  84. for (byte x = 0; x < HorizontalTOTAL; x++){
  85. for (byte y = 0; y < VerticalTOTAL; y++){
  86. //mode selection
  87. //pixel = blank[(y + Yshift) % VerticalTOTAL] [(x + Xshift)%HorizontalTOTAL];
  88. //pixel = sinwave[(y + Yshift) % VerticalTOTAL] [(x + Xshift)%HorizontalTOTAL];
  89. pixel = lines[(y + Yshift) % VerticalTOTAL] [(x + Xshift)%HorizontalTOTAL];
  90. //pixel = diamonds[(y + Yshift) % VerticalTOTAL] [(x + Xshift)%HorizontalTOTAL];
  91. //pixel = wave[(y + Yshift) % VerticalTOTAL] [(x + Xshift)%HorizontalTOTAL];
  92. sat = pixel;
  93. if (pixel != 0){
  94. LEDIndex = HorizontalTOTAL*y+(y%2)*(2*x-9)+(9-x);
  95. leds[LEDIndex] = CHSV(color,255,sat);}}
  96. }
  97. LEDS.show();
  98. delay(8);
  99. }
Advertisement
Add Comment
Please, Sign In to add comment