jsmirnio

Arduino RadioShack RGB LED Strip TM 1803 4th July Patterns

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