CircuitGizmos

Electronic Products for Creative Minds

  • Home
  • Gizmo Store/Products
  • Documentation/Datasheets
  • Projects/Libraries
  • GizmoBlog
  • Services/Contact
    • Design
    • Contact Gizmo!
  • Your Gizmo Cart
    • Your Account
You are here: Home / Projects / MicroBoard MicroMite Projects / APA 102 LED Strip

APA 102 LED Strip

 

This code is a bit of example code for APA 102 LED Strips.

Project by Bill.b.

I have been playing with a 1m length of 60 APA 102 RGB leds for my Christmas light displays.

Here is the program I have been using to test the LEDS. also a youtube video of the results. The code is not pretty as it has been built up as I added different patterns and tried different ways to use the LEDs.

The beauty of the APA 102 LEDs are that they do not require any Cfunction code.

The APA 102 require a 5v supply but the clock and data inputs work quite well on 3.3v from the PICMX170.

https://www.youtube.com/watch?v=IRmtGD0kJVo

 

mm_apa102

The 100 ohm resistors are to protect the inputs if a fault develops in the LEDs.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
'Test Program for APA102 60 RGB LED Strip
  Option autorun on
  Option DEFAULT NONE
  cpu 48
' Option EXPLICIT
  randomize timer
  Dim integer count, count1, rndnum, loopcnt, indexcount
  Dim INTEGER NUMLEDS=60
  Dim integer buffer(183)
  Dim integer red1, red
  Dim integer green1, green
  Dim integer blue1, blue
  SPI open 5000000, 3,8
  For count = 0 To 180  'Reset all LED to OFF
    buffer(count) = 0
  Next count
  sendLED
  Pause 100
  
  main
  
Sub app102Head    ' Send the start of data header
  SPI write 4, &H00,&H00,&H00,&H00
End Sub
  
Sub app102tail   'Send the end of data tail
  SPI write 4, &HFF,&HFF,&HFF,&HFF
End Sub
  
Sub main
  Do
  for count1 = 1 to 6
  getcolour         'set colour randomly
        'Flash all leds  
    For count = 0 To 178 Step 3
      buffer(count) = Red   'RED
      buffer(count+1) = green  'Green
      buffer(count+2) = blue    'Blue
    Next count
    sendLED
     Pause 1000
next count1
    Pause 1000
    
    For count = 0 To 180 'turn all leds OFF
      buffer(count) = 0
    Next count
    sendLED
    getcolour       'set colour randomly
    for loopcnt = 1 to 4
    For count1 = 0 To 178 Step 3
      buffer(count1) = red
      buffer(count1+1) = green
      buffer(count1+2) = blue
      sendLED
      Pause 20
    Next count1
     getcolour
    
    For count1 = 183 To 2 Step -3
      buffer(count1-2) = red
      buffer(count1-1) = green
      buffer(count1) = blue
      sendLED
      Pause 10
    Next count1
    next loopcnt
    pause 1000
    For count = 0 To 180  'Reset all LED to OFF
      buffer(count) = 0
    Next count
    sendLED
    '   Random display
    Pause 100
    for count1 = 1 to 150         'repeat random lights 150 times
      for count = 0 to 5
        rndnum = Int(RND()*180)+1           'Set array size and set data - Number of LEDs * 3
        Buffer(rndnum) = count * 10 and 10  'Set Brightness of LED
      next count
      sendLED
      pause 100
    next count1
    sendLED
    pause 900
    'Kit scanner
    For count = 0 To 183    'turn all leds OFF
      buffer(count) = 0
    Next count
    sendLED
    for loopcnt = 1 to 2
      for count1 = 5 to 180 step 3     'Run the Red LED from end to end and return
            Buffer(count1) = 30
        sendLED  
               Buffer(count1-3) = 0
        sendLED  
      next count1
      for count1 = 179 to 0 step -3    
        Buffer(count1) = 30
        sendLED  
        Buffer(count1+3) = 0
        sendLED  
      next count1
    next loopcnt
    pause 10
    for count1 = 1 to 12
    for loopcnt = 0 to 179
    read buffer(loopcnt)
    next loopcnt
    sendLED  
    pause 50
    next count1
    pause 2000
    restore
    
    
     For count = 0 To 183    'turn all leds OFF
      buffer(count) = 0
    Next count
    sendLED
      For count = 0 To 183  step 3  'turn all leds OFF
      buffer(count) = 1
    Next count
    sendLED
     indexcount = 180
     for loopcnt = 1 to 60
        for count1 = 5 to indexcount step 3     'Run the Red LED from end to end and return
          Buffer(count1) = 30
          sendLED  
          Buffer(count1-3) = 0
          sendLED  
        next count1
        indexcount = indexcount -3
      next loopcnt
      
          For count = 0 To 180    'turn all leds OFF
      buffer(count) = 0
    Next count
    sendLED
      For count = 0 To 180  step 3  'turn all leds OFF
      buffer(count+2) = 1
    Next count
    sendLED
     indexcount = 180
     for loopcnt = 1 to 60
        for count1 = 4 to indexcount step 3     'Run the Red LED from end to end and return
          Buffer(count1) = 30
          sendLED  
          Buffer(count1-3) = 0
          sendLED  
        next count1
        indexcount = indexcount -3
      next loopcnt
      
  Loop
  
Sub sendLED             ' Send a LED controlling command
  app102head
  For count = 0 To 178 Step 3
    red1 = buffer(count)
    green1 = buffer(count + 1)
    blue1 = buffer(count + 2)
    SPI write 4, &HFF, red1, green1, blue1
  Next count
  app102tail
End Sub
 
'get random colour
  sub getcolour
      red = Int(RND()*5)+1
     red = red * 10 and 10
      green = Int(RND()*5)+1
     green = green * 10 and 10
      blue = Int(RND()*5)+1
     blue = blue * 10 and 10
  end sub
 
        ' Data for LED strip   00 = OFF   255 = Max ON   30 is normal brightness                   LED Number
  
     '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 30,00,00,00,30,00,00,00,30,30,00,00,00,30,00,00,00,30,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 30,00,00,00,30,00,00,00,30,30,00,00,00,30,00,00,00,30,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 30,00,00,00,30,00,00,00,30,30,00,00,00,30,00,00,00,30,00,00,00,00,00,00,00,00,00,00,00,00  ' 21 to 30
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30  ' 51 to 60
  
    '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,00,30,30,00,00,00,30,00,00,00,30,30,00,00,00,30,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,00,30,30,00,00,00,30,00,00,00,30,30,00,00,00,30,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,00,30,30,00,00,00,30,00,00,00,30,30,00,00,00,30,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 21 to 30
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,00,00,00  ' 51 to 60
  
     '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,30,00,00,00,30,30,00,00,00,30,00,00,00,30,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,30,00,00,00,30,30,00,00,00,30,00,00,00,30,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,30,00,00,00,30,30,00,00,00,30,00,00,00,30,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 21 to 30
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,00,00,00,00,00,00  ' 51 to 60
  
     '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,30,00,00,00,30,30,00,00,00,30,00,00,00,30,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,30,00,00,00,30,30,00,00,00,30,00,00,00,30,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,30,00,00,00,30,30,00,00,00,30,00,00,00,30,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 21 to 30
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,00,00,00,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,00,00,00,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,00,00,00,00,00,00,00,00,00  ' 51 to 60
  
     '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,00,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30  ' 21 to 30
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30  ' 51 to 60
  
    '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,00,30,00,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,00,00,30  ' 21 to 30
  data 00,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,00,00,30  ' 51 to 60
  
     '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,00,30,00,30,00,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,00,00,30,00,00,00,30  ' 21 to 30
  data 00,30,00,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,00,00,30,00,00,00,30  ' 51 to 60
  
     '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,00,30,00,30,00,30,00,00,00,30,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,30,30,00,00,00,30,00,00,00,30  ' 21 to 30
  data 00,30,00,30,00,00,00,03,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,30,30,00,00,00,30,00,00,00,30  ' 51 to 60
  
     '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,00,30,00,30,00,30,00,00,00,30,30,30,00,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,30,00,00,00,30,00,00,00,30  ' 21 to 30
  data 00,30,00,30,00,00,00,03,30,30,00,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,30,00,30,00,30,30,30,00,00,00,30,00,00,00,30  ' 51 to 60
  
     '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,00,30,00,30,00,30,00,00,00,30,30,30,00,30,30,30,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,00,00,00,00,00,00,00,00,00,00,00,30,30,00,30,00,30,00,30,30,30,00,00,00,30,00,00,00,30  ' 21 to 30
  data 00,30,00,30,00,00,00,03,30,30,00,30,30,30,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,00,00,00,30,30,00,30,00,30,00,30,30,30,00,00,00,30,00,00,00,30  ' 51 to 60
  
    '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,00,30,00,30,00,30,00,00,00,30,30,30,00,30,30,30,00,30,30,30,00,00,00,00,00,00,00,00,00  ' 1 to 10
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,00,00,00,00,00,00,00,00,30,30,30,30,30,00,30,00,30,00,30,30,30,00,00,00,30,00,00,00,30  ' 21 to 30
  data 00,30,00,30,00,00,00,03,30,30,00,30,30,30,00,30,30,30,00,00,00,00,00,00,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,00,00,00,00,00,00,30,30,30,30,30,00,30,00,30,00,30,30,30,00,00,00,30,00,00,00,30  ' 51 to 60
  
     '| B  G  R| B  G  R |B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R| B  G  R|    
  data 00,00,30,00,30,00,30,00,00,00,30,30,30,00,30,30,30,00,30,30,30,10,10,20,30,00,10,00,00,00  ' 1 to 10
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 11 to 20
  data 00,00,00,30,00,10,10,10,20,30,30,30,30,30,00,30,00,30,00,30,30,30,00,00,00,30,00,00,00,30  ' 21 to 30
  data 00,30,00,30,00,00,00,30,30,30,00,30,30,30,00,30,30,30,10,10,20,30,00,10,00,00,00,00,00,00  ' 31 to 40
  data 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00  ' 41 to 50
  data 00,00,00,30,00,10,10,10,20,30,30,30,30,30,00,30,00,30,00,30,30,30,00,00,00,30,00,00,00,30  ' 51 to 60

 

 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

A Ton of Documentation

Open all | Close all

Projects made by Gizmo, Friends, and Members

open all | close all

Recent GizmoBlog Musings

  • Altair 8800 using a ColorMax!
  • Re-energizing the ColorMax, Pt. 3

Visit us!

  • Facebook

Electronic Products for Creative Minds

CircuitGizmos is your source for electronic products that help you create your embedded projects. Here at CircuitGizmos.com you will find a friendly store filled with creative products and all of the documentation that you need to use these gizmos.

We create devices that we believe make electronics fun, but we also know that our products are used for professional designs. For decades we have designed products for commercial, military, and medical industries. Our gizmos here are great for engineers and hobbyists alike.

Copyright © 2008+ CircuitGizmos, L.L.C. All rights reserved

Image already added

Recently Viewed Products

Copyright © 2021 · Generate Pro Theme on Genesis Framework · WordPress · Log in