jsmirnio

Arduino RadioShack LED Strip 4th of July

Jun 29th, 2014
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.20 KB | None | 0 0
  1. /* RadioShack LED Strip - Arduino One-Pin Control
  2. Holiday Spirit - Fourth of July 2014
  3. */
  4. /*
  5. RadioShack Tri Color LED strip light show.
  6. This is the default code from RS - with some annotations to help explain
  7. what is happening
  8. */
  9.  
  10. #include <avr/pgmspace.h>
  11.  
  12. // ******** DEBUG ==== should auto config to adapt different mother board *********
  13. //#define DATA_1 (PORTF |=  0X01)    // DATA 1    // for ATMEGA
  14. //#define DATA_0 (PORTF &=  0XFE)    // DATA 0    // for ATMEGA
  15. //#define STRIP_PINOUT DDRF=0xFF  // for ATMEGA
  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 will assign values to store in the AVR chip's RAM memory as a two dimensional array.
  25.  
  26. We will then read out these values to create a serial pulse train OUTPUT to the LED Strip.
  27.  
  28. Each ROW is sent as OUTPUT and will SET the COLOR for each of the TEN (10) nodes .  
  29.  
  30. Each ROW is a NEW FRAME, changing the colors again and again, creating a pattern.
  31.  
  32. The order of the doublets (byte) controlling the COLORS is: Green - Blue - Red.
  33. ff is full brightness - so 0xff0000 is GREEN, 0xx00ff00 is BLUE, 0x0000ff is RED
  34. */
  35.  
  36. // RED is the last doublet
  37. PROGMEM const unsigned long pattern_test_red[10][10]={
  38.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  39.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  40.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  41.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  42.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  43.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  44.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  45.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  46.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  47.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  48. };
  49.  
  50. // WHITE is ALL doublets
  51. PROGMEM const unsigned long pattern_test_white[10][10]={
  52.   {0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  53.   {0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  54.   {0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  55.   {0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  56.   {0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000},
  57.   {0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000,0x000000},
  58.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000,0x000000},
  59.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000,0x000000},
  60.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x000000},
  61.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd},
  62. };
  63.  
  64. // BLUE is the second doublet
  65. PROGMEM const unsigned long pattern_test_blue[10][10]={
  66.   {0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  67.   {0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  68.   {0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  69.   {0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  70.   {0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000,0x000000},
  71.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000,0x000000},
  72.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000,0x000000},
  73.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000,0x000000},
  74.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000,0x000000},
  75.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00f000},
  76. };
  77.  
  78. // GREEN is the first doublet
  79. PROGMEM const unsigned long pattern_test_green[10][10]={
  80.   {0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  81.   {0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  82.   {0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  83.   {0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  84.   {0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000,0x000000},
  85.   {0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000,0x000000},
  86.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000,0x000000},
  87.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000,0x000000},
  88.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000,0x000000},
  89.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xf00000},
  90. };
  91.  
  92. // Each ROW changes which LED is bright, creating a moving pattern
  93. PROGMEM const unsigned long pattern_test_comet1[][10]={
  94.   {0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  95.   {0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  96.   {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  97.   {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  98.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000},
  99.   {0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000},
  100.   {0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000},
  101.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000},
  102.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000},
  103.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd},
  104. };
  105.  
  106. PROGMEM const unsigned long pattern_test_comet2[][10]={
  107.   {0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000},
  108.   {0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000},
  109.   {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000},
  110.   {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000},
  111.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd},
  112.   {0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000},
  113.   {0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000},
  114.   {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000},
  115.   {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000},
  116.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x111111,0x444444,0xfdfdfd},
  117. };
  118.  
  119. PROGMEM const unsigned long pattern_test_comet3[][10]={
  120.   {0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd},
  121.   {0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x444444},
  122.   {0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0x000000,0x000000,0xfdfdfd,0x444444,0x111111},
  123.   {0x000000,0x111111,0x444444,0xfdfdfd,0x000000,0x000000,0xfdfdfd,0x444444,0x111111,0x000000},
  124.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0xfdfdfd,0x444444,0x111111,0x000000,0x000000},
  125.   {0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0xfdfdfd,0x444444,0x111111,0x000000,0x000000},
  126.   {0x000000,0x000000,0x000000,0xfdfdfd,0x444444,0x444444,0xfdfdfd,0x000000,0x000000,0x000000},
  127.   {0x000000,0x000000,0xfdfdfd,0x444444,0x111111,0x111111,0x444444,0xfdfdfd,0x000000,0x000000},
  128.   {0x000000,0xfdfdfd,0x444444,0x111111,0x000000,0x000000,0x111111,0x444444,0xfdfdfd,0x000000},
  129.   {0xfdfdfd,0x444444,0x111111,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xfdfdfd},
  130. };
  131.  
  132. //  Each row changes the color and intensity of the LEDs
  133. PROGMEM const unsigned long pattern_test_rainbow[10][10]={
  134.   {0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000},
  135.   {0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000},
  136.   {0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000},
  137.   {0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd},
  138.   {0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd},
  139.   {0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00,0x0000fd},
  140.   {0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00,0x00fd00},
  141.   {0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00,0xfdfd00},
  142.   {0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x000000,0x000000,0x000000,0xfd0000,0xfd7f00},
  143.   {0xfd7f00,0xfdfd00,0x00fd00,0x0000fd,0x6f00fd,0x8f00fd,0x0000fd,0x00fd00,0xfdfd00,0xfdfd00},
  144. };
  145.  
  146. PROGMEM const unsigned long cylon_test_red[10][10]={
  147.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  148.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  149.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  150.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  151.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  152.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  153.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  154.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  155.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  156.   {0x000000,0x000000,0x000000,0x000000,0xf0f0f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  157. };
  158.  
  159. PROGMEM const unsigned long red_cylon_R[][10]={
  160.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  161.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  162.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  163.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  164.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  165.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  166.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  167.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  168.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  169.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  170. };
  171.  
  172. PROGMEM const unsigned long red_cylon_L[][10]={
  173.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  174.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  175.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  176.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  177.   {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  178.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000},
  179.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  180.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  181.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  182.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000},
  183. };
  184.  
  185. PROGMEM const unsigned long star_trek_bridge[10][10]={
  186.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  187.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  188.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  189.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  190.   {0x000000,0x000000,0x000000,0x000000,0x0000f0,0xf000f0,0x000000,0x000000,0x000000,0x000000},
  191.   {0x000000,0x000000,0x000000,0x000000,0xf000f0,0x0000f0,0x000000,0x000000,0x000000,0x000000},
  192.   {0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000},
  193.   {0x000000,0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000,0x000000},
  194.   {0x000000,0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0,0x000000},
  195.   {0x0000f0,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000f0},
  196. };
  197. // ***********************************************************************************************************
  198. // *
  199. // *                            INITIALIZE the system on Power Up or after a RESET
  200. // *
  201. // *
  202. // ***********************************************************************************************************
  203. void setup() {              
  204.  
  205.   STRIP_PINOUT; // sets the output pin to control the LED Strip
  206.   reset_strip();    // resets each of the LED nodes to OFF 
  207.  
  208. }
  209.  
  210.  
  211. // ***********************************************************************************************************
  212. // *
  213. // *                            Main Program Loop
  214. // *
  215. // *
  216. // ***********************************************************************************************************
  217. void loop()
  218. {
  219.  
  220. /*
  221. This is a TEST PATTERN to show that all of the
  222. segments ("nodes") are working properly.
  223. This Runs Only ONCE ... because the next loop
  224. never finishes.  
  225.  
  226. You could remove the WHILE loop and then these patterns
  227. would run continuosly, as long as there is power to the board.
  228. */
  229.   int q = 1;
  230.   send_1M_pattern(pattern_test_green, 10, 500);
  231.   delay(500);
  232.  
  233.   send_1M_pattern(pattern_test_red, 10, 500);
  234.   delay(500);
  235.   send_1M_pattern(pattern_test_white, 10, 500);
  236.   delay(500);
  237.   send_1M_pattern(pattern_test_blue, 10, 500);
  238.   delay(500);
  239.  
  240.   send_1M_pattern(pattern_test_comet1, 10, 70);
  241.   delay(500);
  242.   send_1M_pattern(pattern_test_comet2, 10, 70);
  243.   delay(500);
  244.   send_1M_pattern(pattern_test_comet3, 10, 70);
  245.   delay(500);
  246.  
  247.   send_1M_pattern(pattern_test_green, 10, 500);
  248.   delay(1000); // Wait for one second to make you think about the infinite loop
  249.  
  250.  
  251. /* TEN CYCLES OF TREK BRIDGE */
  252.   q = 20;
  253.   while (q>0){
  254.      send_1M_pattern(star_trek_bridge, 10, 30);
  255.     q -= 1;
  256.   }
  257.   delay(500);
  258.  
  259. /*
  260. Use this to control which pattern is sent to the
  261. LED Strip.
  262.  
  263. This loop runs will run continously inside the "master" loop;
  264. because the value of WHILE (1) never changes.
  265. */
  266.   while (1)
  267.   {
  268.   send_1M_pattern(pattern_test_white, 10, 500);
  269.   delay(500);
  270.   send_1M_pattern(pattern_test_rainbow, 10, 70);
  271.   delay(500);
  272.   send_1M_pattern(pattern_test_green, 10, 500);
  273.   delay(1000); // Wait for one second to make you think about the infinite loop
  274.   send_1M_pattern(cylon_test_red, 10, 70);
  275.   delay(500);
  276.  
  277. /* TEN CYCLES OF CYLON */
  278.   q = 10;
  279.   while (q>0){
  280.     send_1M_pattern(red_cylon_R, 10, 70);
  281.     send_1M_pattern(red_cylon_L, 10, 70);
  282.     q -= 1;
  283.   }
  284.   delay(500);
  285.  
  286. /* TEN CYCLES OF TREK BRIDGE */
  287.   q = 20;
  288.   while (q>0){
  289.      send_1M_pattern(star_trek_bridge, 10, 30);
  290.     q -= 1;
  291.   }
  292.   delay(500);
  293.  
  294. /* 30 CYCLES OF RED-WHITE-BLUE */
  295.   q = 30;
  296.   while (q>0){
  297.   send_1M_pattern(pattern_test_red, 10, 100);
  298.   delay(500);
  299.   send_1M_pattern(pattern_test_white, 10, 100);
  300.   delay(500);
  301.   send_1M_pattern(pattern_test_blue, 10, 100);
  302.   delay(500);
  303.   q -= 1;
  304.   }
  305.   delay(500);
  306.   }
  307. }
  308.  
  309. /*******************************************************************************
  310. * Function Name:    send_1M_pattern
  311. * Description:      Transmit pattern to whole 1 meter strip*                
  312. * Input :       Pointer to RAM pattern; pattern length; frame rate*                
  313. * Output:       Sends out a serial pulse train using the send_strip function
  314. * Return:       None
  315. *******************************************************************************/
  316. void send_1M_pattern(const unsigned long data[][10], int pattern_no, int frame_rate)
  317. {
  318.   int i=0;
  319.   int j=0;
  320.   uint32_t temp_data;
  321.  
  322. // Each pattern sends out [x] packets - one for each NODE (RGB LED cluster)
  323. // pattern_no is the [y] dimension of the array - the number of ROWS in each pattern array set
  324.   for (i=0;i<pattern_no;i++)
  325.   {
  326.     noInterrupts(); // Turn OFF Interupts for more precise Pulse Timing
  327.     for (j=0;j<10;j++)
  328.     {
  329.       temp_data=pgm_read_dword_near(&data[i][j]);
  330.       send_strip(temp_data);
  331.     }
  332.     interrupts(); // Turn ON Interrupts after data is sent
  333.  
  334.     delay(frame_rate); // Delay between each pulse train - sets the duration of each Frame, before the next signal is sent;
  335.     /* CONTROLS THE VISUAL SPEED OF THE DISPLAY CHANGES */
  336.  
  337.   }
  338.  
  339.  
  340. }
  341.  
  342.  
  343. /*******************************************************************************
  344. * Function Name:    send_strip
  345. * Description:      Creates and Transmits a serial train of 24 pulses for the LED strip              
  346. * Input:        24-bit data sets intensity of each color, which will persist until
  347. *           the next cycle makes a change                
  348. * Output:       Sends a train of 24 pulses (bits) representing values of 0 or 1 to the output pin ()
  349. * Return:       Nothing returned from function
  350. *******************************************************************************/
  351. void send_strip(uint32_t data)
  352. {
  353.   int i;
  354.   unsigned long j=0x800000;
  355.  
  356.  
  357.   for (i=0;i<24;i++)
  358.   {
  359.     if (data & j)
  360.     {
  361.       DATA_1;
  362.       __asm__("nop\n\t");
  363.       __asm__("nop\n\t");
  364.       __asm__("nop\n\t");
  365.       __asm__("nop\n\t");
  366.       __asm__("nop\n\t");
  367.       __asm__("nop\n\t");
  368.       __asm__("nop\n\t");
  369.       __asm__("nop\n\t");
  370.       __asm__("nop\n\t");  
  371.       __asm__("nop\n\t");
  372.       __asm__("nop\n\t");
  373.       __asm__("nop\n\t");
  374.       __asm__("nop\n\t");
  375.       __asm__("nop\n\t");
  376.       __asm__("nop\n\t");
  377.       __asm__("nop\n\t");
  378.       __asm__("nop\n\t");
  379.       __asm__("nop\n\t");
  380.    
  381. /*----------------------------*/
  382.       __asm__("nop\n\t");
  383.       __asm__("nop\n\t");
  384.       __asm__("nop\n\t");
  385.       __asm__("nop\n\t");
  386.       __asm__("nop\n\t");
  387.       __asm__("nop\n\t");
  388.       __asm__("nop\n\t");
  389.       __asm__("nop\n\t");
  390.       __asm__("nop\n\t");
  391.       __asm__("nop\n\t");      
  392. /*----------------------------*/    
  393.       DATA_0;
  394.     }
  395.     else
  396.     {
  397.       DATA_1;
  398.       __asm__("nop\n\t");
  399.       __asm__("nop\n\t");
  400.       __asm__("nop\n\t");
  401.       __asm__("nop\n\t");
  402.       __asm__("nop\n\t");
  403.       __asm__("nop\n\t");
  404.       __asm__("nop\n\t");
  405.       __asm__("nop\n\t");
  406.       __asm__("nop\n\t");  
  407.       DATA_0;
  408. /*----------------------------*/    
  409.        __asm__("nop\n\t");
  410.       __asm__("nop\n\t");
  411.       __asm__("nop\n\t");    
  412. /*----------------------------*/      
  413.     }
  414.  
  415.     j>>=1;
  416.   }
  417.  
  418.  
  419. }
  420.  
  421. /*******************************************************************************
  422. * Function Name:    reset_strip
  423. * Description:      Send a 0 pulse to reset all colors on all NODES of the strip*                
  424. * Input:        None*                
  425. * Output:       Sends out a looong value of 0 on the output pin
  426. * Return:       None
  427. *******************************************************************************/
  428. void reset_strip()
  429. {
  430.   DATA_0;
  431.   delayMicroseconds(20);
  432. }
Add Comment
Please, Sign In to add comment