jsmirnio

RadioShack RGB LED Arduino Program

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