Guest User

RadioShack LED Strip Program Code

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