Advertisement
jsmirnio

RadioShack RGB LED Strip Arduino July 4th 2014

Jul 1st, 2014
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 27.25 KB | None | 0 0
  1. /*  HAPPY FOURTH OF JULY TO ALL ARDUINOS !!! */
  2. /*
  3. RadioShack RGB Color LED strip light show.
  4. This is the default code from RS - with some annotations to help explain
  5. what is happening PLUS several NEW Patterns for July 4th 2014
  6. */
  7.  
  8. #include <avr/pgmspace.h>
  9.  
  10. /*
  11. #define DATA_1 (PORTD |= (1<<5)) // Set logic high Pin5 of Port D
  12. #define DATA_0 (PORTD &= ~(1<<5)) // Set Pin5 logic low Pin5 of Port D
  13. #define STRIP_PINOUT DDRD |= (1<<5) // Set Pin5 of PortD as digital output
  14. #define LED_RGB_STRIP
  15. */
  16.  
  17. #define DATA_1 (PORTC |=  0X01)    // DEFINE a value for DATA as 1  // for UNO
  18. #define DATA_0 (PORTC &=  0XFE)    // DEFINE a value for DATA 0   // for UNO
  19. #define STRIP_PINOUT (DDRC=0x3F)  // DEFINE PORTC as OUTPUT // for UNO (change pins 0-5; leave PORTC 6 & 7 alone)
  20.  
  21. /*
  22. Create an array of values to control each LED NODE in the standard RadioShack strip.  
  23.  
  24. PROGMEM stores the data in the AVR chip's PROGRAM memory.  This has much more space than the 2K of variable RAM memory.
  25. The two dimensional array has one value for each one of the 10 TM1803 RGB LEDs - controlling the color.
  26. Each "row" can change the colors assigned.  This is like a FRAME in an animation.  Changing the FRAME's
  27. values can create the animation effect of motion.
  28.  
  29. We will then read out these values one FRAME (row) at a time to create the 24bit serial pulse train that is OUTPUT to the LED Strip.
  30.  
  31. Each ROW is sent as OUTPUT and it will SET the COLOR for each of the TEN (10) nodes.
  32. Each ROW is a NEW FRAME, changing the colors again and again, creating a pattern.
  33.  
  34. The order of the HEX doublets (bytes) controlling the COLORS is: Green - Blue - Red.
  35. ff is full brightness - so 0xff0000 is full GREEN, 0xx00ff00 is full BLUE, 0x0000ff is full RED
  36. */
  37.  
  38. // In the Radio Shack RGB Strip, the TM1803 controls RED with the last HEX byte
  39. PROGMEM const unsigned long pattern_test_red[10][10]={
  40.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  41.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  42.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  43.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  44.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  45.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  46.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  47.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  48.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  49.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  50. };
  51.  
  52. PROGMEM const unsigned long first_red[10][10]={
  53.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  54.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  55.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  56.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  57.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  58.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  59.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  60.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  61.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  62.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  63. };
  64.  
  65. PROGMEM const unsigned long second_red[10][10]={
  66.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  67.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  68.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  69.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  70.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  71.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x0000f0},
  72.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0},
  73.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x0000f0},
  74.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0},
  75.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0},
  76. };
  77.  
  78. PROGMEM const unsigned long first_white[10][10]={
  79.   {0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0},
  80.   {0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0},
  81.   {0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0},
  82.   {0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x0000f0},
  83.   {0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x0000f0,0x0000f0},
  84.   {0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x0000f0,0x0000f0},
  85.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x0000f0,0x0000f0},
  86.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0},
  87.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0},
  88.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0},
  89. };
  90.  
  91. PROGMEM const unsigned long second_white[10][10]={
  92.   {0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0},
  93.   {0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0},
  94.   {0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0},
  95.   {0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0},
  96.   {0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0x000000,0xd0d0d0,0x0000f0,0x0000f0},
  97.   {0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0x000000,0xd0d0d0,0x0000f0,0x0000f0},
  98.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  99.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  100.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  101.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  102. };
  103.  
  104. PROGMEM const unsigned long first_blue[10][10]={
  105.   {0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  106.   {0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  107.   {0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  108.   {0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  109.   {0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  110.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  111.   {0x00f000,0x000000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  112.   {0x000000,0x00f000,0x000000,0x000000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  113.   {0x000000,0x000000,0x00f000,0x000000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  114.   {0x000000,0x000000,0x000000,0x00f000,0x000000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  115. };
  116.  
  117. PROGMEM const unsigned long second_blue[10][10]={
  118.   {0x000000,0x000000,0x000000,0x000000,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  119.   {0x0000f0,0x000000,0x000000,0x000000,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  120.   {0x000000,0x0000f0,0x000000,0x000000,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  121.   {0x000000,0x000000,0x0000f0,0x000000,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  122.   {0x000000,0x000000,0x000000,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  123.   {0x0000f0,0x000000,0x000000,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  124.   {0x000000,0x0000f0,0x000000,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  125.   {0x000000,0x000000,0x0000f0,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  126.   {0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0,0x00f000,0x00f000,0xd0d0d0,0xd0d0d0,0x0000f0,0x0000f0},
  127. };
  128.  
  129.  
  130. // WHITE is ALL HEX bytes (can vary the "color" of white by changing these
  131. PROGMEM const unsigned long pattern_test_white[10][10]={
  132.   {0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  133.   {0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  134.   {0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  135.   {0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  136.   {0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000},
  137.   {0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000},
  138.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000},
  139.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000},
  140.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000},
  141.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd},
  142. };
  143.  
  144. // BLUE is the second HEX byte
  145. PROGMEM const unsigned long pattern_test_blue[10][10]={
  146.   {0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  147.   {0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  148.   {0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  149.   {0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  150.   {0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000},
  151.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000},
  152.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000},
  153.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000},
  154.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000},
  155.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000},
  156. };
  157.  
  158. // GREEN is the first HEX byte
  159. PROGMEM const unsigned long pattern_test_green[10][10]={
  160.   {0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  161.   {0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  162.   {0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  163.   {0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  164.   {0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000},
  165.   {0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000},
  166.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000},
  167.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000},
  168.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000},
  169.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000},
  170. };
  171.  
  172. // Each ROW changes which LED is bright, creating a moving pattern
  173. PROGMEM const unsigned long pattern_test_comet1[][10]={
  174.   {0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  175.   {0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  176.   {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  177.   {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  178.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000},
  179.   {0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000},
  180.   {0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000},
  181.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000},
  182.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000},
  183.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd},
  184. };
  185.  
  186. PROGMEM const unsigned long pattern_test_comet2[][10]={
  187.   {0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000},
  188.   {0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000},
  189.   {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000},
  190.   {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000},
  191.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd},
  192.   {0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000},
  193.   {0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000},
  194.   {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000},
  195.   {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000},
  196.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd},
  197. };
  198.  
  199. PROGMEM const unsigned long pattern_test_comet3[][10]={
  200.   {0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd},
  201.   {0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x444444},
  202.   {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x444444,0x111111},
  203.   {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0xfdfdfd,0x444444,0x111111,0x000000},
  204.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0xfdfdfd,0x444444,0x111111,0x000000,0x000000},
  205.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0xfdfdfd,0x444444,0x111111,0x000000,0x000000},
  206.   {0x000000,0x000000,0x000000,0xfdfdfd,0x444444,0x444444,0xfdfdfd,0x000000,0x000000,0x000000},
  207.   {0x000000,0x000000,0xfdfdfd,0x444444,0x111111,0x111111,0x444444,0xfdfdfd,0x000000,0x000000},
  208.   {0x000000,0xfdfdfd,0x444444,0x111111,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000},
  209.   {0xfdfdfd,0x444444,0x111111,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd},
  210. };
  211.  
  212. //  Each row changes the color and intensity of the LEDs
  213. PROGMEM const unsigned long pattern_test_rainbow[10][10]={
  214.   {0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000},
  215.   {0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000},
  216.   {0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000},
  217.   {0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd},
  218.   {0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd},
  219.   {0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd},
  220.   {0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00},
  221.   {0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00},
  222.   {0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00},
  223.   {0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x0000fd,0x00fd00,0xfdfd00,0xfdfd00},
  224. };
  225.  
  226. PROGMEM const unsigned long cylon_test_red[10][10]={
  227.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  228.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  229.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  230.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  231.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  232.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  233.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  234.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  235.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  236.   {0x000000,0x000000,0x000000,0x000000,0xf0f0f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  237. };
  238.  
  239. PROGMEM const unsigned long red_cylon_R[][10]={
  240.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  241.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  242.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  243.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  244.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  245.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  246.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  247.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  248.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  249.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  250. };
  251.  
  252. PROGMEM const unsigned long red_cylon_L[][10]={
  253.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  254.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  255.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  256.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  257.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  258.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  259.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  260.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  261.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  262.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  263. };
  264.  
  265. PROGMEM const unsigned long star_trek_bridge[10][10]={
  266.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  267.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  268.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  269.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  270.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0xf000f0,0x000000,0x000000,0x000000,0x000000},
  271.   {0x000000,0x000000,0x000000,0x000000,0xf000f0,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  272.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  273.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  274.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  275.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  276. };
  277. // ***********************************************************************************************************
  278. // *
  279. // *                            INITIALIZE the system on Power Up or after a RESET
  280. // *
  281. // *
  282. // ***********************************************************************************************************
  283. void setup() {              
  284.  
  285.   STRIP_PINOUT; // sets the output pin to control the LED Strip
  286.   reset_strip();    // resets each of the LED nodes to OFF 
  287.  
  288. }
  289.  
  290.  
  291. // ***********************************************************************************************************
  292. // *
  293. // *                            Main Program Loop
  294. // *
  295. // *
  296. // ***********************************************************************************************************
  297. void loop()
  298. {
  299.  
  300. /*
  301. This is a TEST PATTERN to show that all of the
  302. segments ("nodes") are working properly.
  303. This Runs Only ONCE ... because the next loop
  304. never finishes.  
  305.  
  306. You could remove the WHILE loop and then these patterns
  307. would run continuously, as long as there is power to the board.
  308. */
  309.   int q = 1;
  310.   send_1M_pattern(pattern_test_green, 10, 50);
  311.   delay(500);
  312.   send_1M_pattern(pattern_test_blue, 10, 500);
  313.   delay(500);
  314.   send_1M_pattern(pattern_test_red, 10, 500);
  315.   delay(500);
  316.  
  317.   send_1M_pattern(pattern_test_white, 10, 500);
  318.   delay(500);
  319.  
  320.   send_1M_pattern(pattern_test_comet1, 10, 70);
  321.   delay(500);
  322.   send_1M_pattern(pattern_test_comet2, 10, 70);
  323.   delay(500);
  324.   send_1M_pattern(pattern_test_comet3, 10, 70);
  325.   delay(500);
  326.  
  327. /* RAINBOW TEST PATTERN */  
  328.   send_1M_pattern(pattern_test_rainbow, 10, 100);
  329.   delay(1000); // Wait for one second to make you think about the infinite loop
  330.  
  331.  
  332. /* TEN CYCLES OF TREK BRIDGE */
  333.   q = 10;
  334.   while (q>0){
  335.      send_1M_pattern(star_trek_bridge, 10, 50);
  336.     q -= 1;
  337.   }
  338.   delay(500);
  339.  
  340. /*
  341. Use this to control which pattern is sent to the
  342. LED Strip.
  343.  
  344. This loop runs will run continuously inside the "master" loop;
  345. because the value of WHILE (1) never changes.
  346. */
  347.   while (1)
  348.   {
  349.   send_1M_pattern(pattern_test_white, 10, 100);
  350.   delay(500);
  351.   send_1M_pattern(pattern_test_rainbow, 10, 100);
  352.   delay(500);
  353.   send_1M_pattern(pattern_test_green, 10, 50);
  354.   delay(1000); // Wait for one second to make you think about the infinite loop
  355.  
  356. /* RAINBOW TEST PATTERN */  
  357.   send_1M_pattern(pattern_test_rainbow, 10, 100);
  358.   delay(1000); // Wait for one second to make you think about the infinite loop
  359.  
  360. /* TEN CYCLES OF CYLON */
  361.   q = 10;
  362.   while (q>0){
  363.     send_1M_pattern(cylon_test_red, 10, 100);
  364.     delay(500);
  365.     send_1M_pattern(red_cylon_R, 10, 70);
  366.     send_1M_pattern(red_cylon_L, 10, 70);
  367.     q -= 1;
  368.   }
  369.   delay(500);
  370.  
  371.  
  372. /* 5 CYCLES OF SIMPLE RED-WHITE-BLUE */
  373.   q = 5;
  374.   while (q>0){
  375.   send_1M_pattern(pattern_test_red, 10, 100);
  376.   delay(500);
  377.   send_1M_pattern(pattern_test_white, 10, 100);
  378.   delay(500);
  379.   send_1M_pattern(pattern_test_blue, 10, 100);
  380.   delay(500);
  381.   q -= 1;
  382.   }
  383.   delay(500);
  384.  
  385. /* FIVE CYCLES OF TREK BRIDGE */
  386.   q = 5;
  387.   while (q>0){
  388.      send_1M_pattern(star_trek_bridge, 10, 60);
  389.     q -= 1;
  390.   }
  391.   delay(500);
  392.  
  393. /* 10 CYCLES OF RED-WHITE-BLUE BUILD UP */
  394.   q = 10;
  395.   while (q>0){
  396.   send_1M_pattern(first_red, 10, 100);
  397.   delay(500);
  398.   send_1M_pattern(second_red, 10, 100);
  399.   delay(500);
  400.   send_1M_pattern(first_white, 10, 100);
  401.   delay(500);
  402.   send_1M_pattern(second_white, 10, 100);
  403.   delay(500);
  404.   send_1M_pattern(first_blue, 10, 100);
  405.   delay(500);
  406.   send_1M_pattern(second_blue, 10, 100);
  407.   delay(1000);
  408.   q -= 1;
  409.   }
  410.   delay(500);
  411.  
  412.   } // END OF WHILE (1)
  413. } // END OF VOID LOOP() - otherwise known as MAIN();
  414.  
  415. /*******************************************************************************
  416. * Function Name:    send_1M_pattern
  417. * Description:      Transmit pattern to whole 1 meter strip*                
  418. * Input :       Pointer to RAM pattern; pattern length; frame rate*                
  419. * Output:       Sends out a serial pulse train using the send_strip function
  420. * Return:       None
  421. *******************************************************************************/
  422. void send_1M_pattern(const unsigned long data[][10], int pattern_no, int frame_rate)
  423. {
  424.   int i=0;
  425.   int j=0;
  426.   uint32_t temp_data;
  427.  
  428. // Each pattern sends out [x] packets - one for each NODE (RGB LED cluster)
  429. // pattern_no is the [y] dimension of the array - the number of ROWS in each pattern array set
  430.   for (i=0;i<pattern_no;i++)
  431.   {
  432.     noInterrupts(); // Turn OFF Interupts for more precise Pulse Timing
  433.     for (j=0;j<10;j++)
  434.     {
  435.       temp_data=pgm_read_dword_near(&data[i][j]);
  436.       send_strip(temp_data);
  437.     }
  438.     interrupts(); // Turn ON Interrupts after data is sent
  439.  
  440.     delay(frame_rate); // Delay between each pulse train - sets the duration of each Frame, before the next signal is sent;
  441.     /* CONTROLS THE VISUAL SPEED OF THE DISPLAY CHANGES */
  442.  
  443.   }
  444.  
  445.  
  446. }
  447.  
  448.  
  449. /*******************************************************************************
  450. * Function Name:    send_strip
  451. * Description:      Creates and Transmits a serial train of 24 pulses for the LED strip              
  452. * Input:        24-bit data sets intensity of each color, which will persist until
  453. *           the next cycle makes a change                
  454. * Output:       Sends a train of 24 pulses (bits) representing values of 0 or 1 to the output pin ()
  455. * Return:       Nothing returned from function
  456. *******************************************************************************/
  457. void send_strip(uint32_t data)
  458. {
  459.   int i;
  460.   unsigned long j=0x800000;
  461.  
  462.  
  463.   for (i=0;i<24;i++)
  464.   {
  465.     if (data & j)
  466.     {
  467.       DATA_1; // SEND TM1803 a HIGH BIT;
  468.       __asm__("nop\n\t");
  469.       __asm__("nop\n\t");
  470.       __asm__("nop\n\t");
  471.       __asm__("nop\n\t");
  472.       __asm__("nop\n\t");
  473.       __asm__("nop\n\t");
  474.       __asm__("nop\n\t");
  475.       __asm__("nop\n\t");
  476.       __asm__("nop\n\t");  
  477.       __asm__("nop\n\t");
  478.       __asm__("nop\n\t");
  479.       __asm__("nop\n\t");
  480.       __asm__("nop\n\t");
  481.       __asm__("nop\n\t");
  482.       __asm__("nop\n\t");
  483.       __asm__("nop\n\t");
  484.       __asm__("nop\n\t");
  485.       __asm__("nop\n\t");
  486.    
  487. /*----------------------------*/
  488.       __asm__("nop\n\t");
  489.       __asm__("nop\n\t");
  490.       __asm__("nop\n\t");
  491.       __asm__("nop\n\t");
  492.       __asm__("nop\n\t");
  493.       __asm__("nop\n\t");
  494.       __asm__("nop\n\t");
  495.       __asm__("nop\n\t");
  496.       __asm__("nop\n\t");
  497.       __asm__("nop\n\t");      
  498. /*----------------------------*/    
  499.       DATA_0;
  500.     }
  501.     else
  502.     { // SEND TM1803 a LOW BIT;
  503.       DATA_1;
  504.       __asm__("nop\n\t");
  505.       __asm__("nop\n\t");
  506.       __asm__("nop\n\t");
  507.       __asm__("nop\n\t");
  508.       __asm__("nop\n\t");
  509.       __asm__("nop\n\t");
  510.       __asm__("nop\n\t");
  511.       __asm__("nop\n\t");
  512.       __asm__("nop\n\t");  
  513.       DATA_0;
  514. /*----------------------------*/    
  515.        __asm__("nop\n\t");
  516.       __asm__("nop\n\t");
  517.       __asm__("nop\n\t");    
  518. /*----------------------------*/      
  519.     }
  520.  
  521.     j>>=1;
  522.   }
  523.  
  524.  
  525. }
  526.  
  527. /*******************************************************************************
  528. * Function Name:    reset_strip
  529. * Description:      Send a 0 pulse to reset all colors on all NODES of the strip*                
  530. * Input:        None*                
  531. * Output:       Sends out a looong value of 0 on the output pin to RESET
  532. * Return:       None
  533. *******************************************************************************/
  534. void reset_strip()
  535. {
  536.   DATA_0;
  537.   delayMicroseconds(20);
  538. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement