├── .gitattributes
├── .gitignore
├── LICENSE.txt
├── README.md
├── examples
├── BasicAnimations
│ ├── AnimationCreator.class
│ ├── AnimationCreator.java
│ ├── Arduino.png
│ ├── BasicAnimations.pde
│ └── ani_arduino.h
├── BasicUse
│ └── BasicUse.pde
├── CircularLightBuffer
│ └── CircularLightBuffer.pde
├── FadeScope
│ └── FadeScope.pde
├── Fades
│ └── Fades.pde
├── Servos
│ └── Servos.pde
└── UsingProgmem
│ └── UsingProgmem.pde
├── extras
├── README.md
├── changelog.txt
└── pinouts
│ ├── ATmega_8.h
│ ├── ATmega_xx4.h
│ ├── ATmega_xx8.h
│ ├── Arduino_Mega.h
│ ├── Teensy_xxU4.h
│ ├── Teensypp_xxx6.h
│ └── chip_includes.h
├── keywords.txt
├── library.properties
└── src
├── SparkFun_Tlc5940.cpp
├── SparkFun_Tlc5940.h
├── pinouts
├── ATmega_8.h
├── ATmega_xx4.h
├── ATmega_xx8.h
├── Arduino_Mega.h
├── Teensy_xxU4.h
├── Teensypp_xxx6.h
└── chip_includes.h
├── tlc_animations.h
├── tlc_config.h
├── tlc_fades.h
├── tlc_progmem_utils.h
├── tlc_servos.h
└── tlc_shifts.h
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## SparkFun Useful stuff
3 | #################
4 |
5 | ## AVR Development
6 | *.eep
7 | *.elf
8 | *.lst
9 | *.lss
10 | *.sym
11 | *.d
12 | *.o
13 | *.srec
14 | *.map
15 |
16 | ## Notepad++ backup files
17 | *.bak
18 |
19 | ## BOM files
20 | *bom*
21 |
22 | #################
23 | ## Eclipse
24 | #################
25 |
26 | *.pydevproject
27 | .project
28 | .metadata
29 | bin/
30 | tmp/
31 | *.tmp
32 | *.bak
33 | *.swp
34 | *~.nib
35 | local.properties
36 | .classpath
37 | .settings/
38 | .loadpath
39 |
40 | # External tool builders
41 | .externalToolBuilders/
42 |
43 | # Locally stored "Eclipse launch configurations"
44 | *.launch
45 |
46 | # CDT-specific
47 | .cproject
48 |
49 | # PDT-specific
50 | .buildpath
51 |
52 |
53 | #############
54 | ## Eagle
55 | #############
56 |
57 | # Ignore the board and schematic backup files
58 | *.b#?
59 | *.s#?
60 |
61 |
62 | #################
63 | ## Visual Studio
64 | #################
65 |
66 | ## Ignore Visual Studio temporary files, build results, and
67 | ## files generated by popular Visual Studio add-ons.
68 |
69 | # User-specific files
70 | *.suo
71 | *.user
72 | *.sln.docstates
73 |
74 | # Build results
75 | [Dd]ebug/
76 | [Rr]elease/
77 | *_i.c
78 | *_p.c
79 | *.ilk
80 | *.meta
81 | *.obj
82 | *.pch
83 | *.pdb
84 | *.pgc
85 | *.pgd
86 | *.rsp
87 | *.sbr
88 | *.tlb
89 | *.tli
90 | *.tlh
91 | *.tmp
92 | *.vspscc
93 | .builds
94 | *.dotCover
95 |
96 | ## TODO: If you have NuGet Package Restore enabled, uncomment this
97 | #packages/
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opensdf
104 | *.sdf
105 |
106 | # Visual Studio profiler
107 | *.psess
108 | *.vsp
109 |
110 | # ReSharper is a .NET coding add-in
111 | _ReSharper*
112 |
113 | # Installshield output folder
114 | [Ee]xpress
115 |
116 | # DocProject is a documentation generator add-in
117 | DocProject/buildhelp/
118 | DocProject/Help/*.HxT
119 | DocProject/Help/*.HxC
120 | DocProject/Help/*.hhc
121 | DocProject/Help/*.hhk
122 | DocProject/Help/*.hhp
123 | DocProject/Help/Html2
124 | DocProject/Help/html
125 |
126 | # Click-Once directory
127 | publish
128 |
129 | # Others
130 | [Bb]in
131 | [Oo]bj
132 | sql
133 | TestResults
134 | *.Cache
135 | ClientBin
136 | stylecop.*
137 | ~$*
138 | *.dbmdl
139 | Generated_Code #added for RIA/Silverlight projects
140 |
141 | # Backup & report files from converting an old project file to a newer
142 | # Visual Studio version. Backup files are not needed, because we have git ;-)
143 | _UpgradeReport_Files/
144 | Backup*/
145 | UpgradeLog*.XML
146 |
147 |
148 | ############
149 | ## Windows
150 | ############
151 |
152 | # Windows image file caches
153 | Thumbs.db
154 |
155 | # Folder config file
156 | Desktop.ini
157 |
158 |
159 | #############
160 | ## Python
161 | #############
162 |
163 | *.py[co]
164 |
165 | # Packages
166 | *.egg
167 | *.egg-info
168 | dist
169 | build
170 | eggs
171 | parts
172 | bin
173 | var
174 | sdist
175 | develop-eggs
176 | .installed.cfg
177 |
178 | # Installer logs
179 | pip-log.txt
180 |
181 | # Unit test / coverage reports
182 | .coverage
183 | .tox
184 |
185 | #Translations
186 | *.mo
187 |
188 | #Mr Developer
189 | .mr.developer.cfg
190 |
191 | # Mac crap
192 | .DS_Store
193 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | SparkFun TLC5940 Arduino Library
2 | ========================================
3 |
4 | The TLC5940 gives the user 16 channel PWM control and can be daisy chained over the serial interface.
5 | This library works with the SparkFun LED Driver Breakout and the SparkFun PWM Shield.
6 |
7 | This library is forked from the original library by Alex Leone, available [here](https://code.google.com/p/tlc5940arduino/).
8 |
9 | Repository Contents
10 | -------------------
11 |
12 | * **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
13 | * **/extras** - Additional documentation for the user. These files are ignored by the IDE.
14 | * **/src** - Source files for the library (.cpp, .h).
15 | * **keywords.txt** - Keywords from this library that will be highlighted in the Arduino IDE.
16 | * **library.properties** - General library properties for the Arduino package manager.
17 |
18 | Documentation
19 | --------------
20 |
21 | * **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
22 | * **[SparkFun LED Driver Breakout- TLC5940](https://github.com/sparkfun/LED_Driver_Breakout-TLC5940)** - Main repository (including hardware files) for the LED Driver Breakout.
23 | * **[SparkFun PWM Shield](https://github.com/sparkfun/PWM_Shield)** - Main repository (including hardware files) for the PWM Shield.
24 |
25 | Products that use this Library
26 | ---------------------------------
27 |
28 | * [BOB-10616](https://www.sparkfun.com/products/10616)- SparkFun LED Driver Breakout-TLC5940
29 | * [DEV-10615](https://www.sparkfun.com/products/10615)- SparkFun PWM Shield
30 |
31 |
32 | License Information
33 | -------------------
34 |
35 | This product is _**open source**_!
36 |
37 | The code is released under GPL.
38 |
39 | Distributed as-is; no warranty is given.
40 |
41 | - Your friends at SparkFun.
42 |
43 | __
44 |
--------------------------------------------------------------------------------
/examples/BasicAnimations/AnimationCreator.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sparkfun/SparkFun_TLC5940_Arduino_Library/df219716b7b08d252adabeb9474a56f7421e0ad4/examples/BasicAnimations/AnimationCreator.class
--------------------------------------------------------------------------------
/examples/BasicAnimations/AnimationCreator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * First Attempt at generating the TLC output code from an image.
3 | * Run this with "java AnimationCreator"
4 | * It will read any image file in the current directory and create an animation for the TLC library.
5 | *
6 | * Right now this only works with 1 TLC with 16 LEDS connected to it, where
7 | * output0 is the bottom and output15 is the top.
8 | *
9 | * For best results make your files 16 pixels high and as wide as you want. Each vertical pixel
10 | * corresponds to an LED output.
11 | *
12 | * Alex Leone , 2008-11-12
13 | */
14 |
15 | import java.util.*;
16 | import java.awt.*;
17 | import java.awt.image.*;
18 | import java.io.*;
19 | import javax.imageio.*;
20 |
21 | public class AnimationCreator {
22 |
23 | public static void main(String[] args) throws IOException {
24 | if (args.length == 0) {
25 | autoProcess();
26 | }
27 | }
28 |
29 | public static void autoProcess() throws IOException {
30 | File currentDirectory = new File (".");
31 | File[] files = currentDirectory.listFiles();
32 | int animationCount = 1;
33 | for (File file : files) {
34 | if (!file.isFile())
35 | continue;
36 | String fileName = file.getName();
37 | String suffix = fileName.substring(fileName.indexOf('.') + 1);
38 | if(!canReadFormat(suffix))
39 | continue;
40 | String baseName = fileName.substring(0, fileName.indexOf('.'));
41 | String varName = "ani_" + baseName.toLowerCase();
42 | String outputName = varName + ".h";
43 | System.out.println("Writing " + outputName);
44 | BufferedImage image = ImageIO.read(file);
45 | PrintStream output = new PrintStream(new File(outputName));
46 | output.println("#define " + varName.toUpperCase() + "_FRAMES " + image.getWidth());
47 | output.println("uint8_t " + varName + "[NUM_TLCS * 24 * " + varName.toUpperCase() + "_FRAMES] PROGMEM = {");
48 | int[] rowRGB = new int[16];
49 | for (int w = 0; w < image.getWidth(); w++) {
50 | for (int h = 0; h < 16; h++) {
51 | rowRGB[h] = image.getRGB(w, 15 - h);
52 | }
53 | parseRow(rowRGB, output);
54 | }
55 | output.println("};");
56 | System.out.println("Wrote " + image.getWidth() + " frames to " + outputName);
57 | animationCount++;
58 | }
59 | }
60 |
61 | // Returns true if the specified format name can be read
62 | public static boolean canReadFormat(String formatName) {
63 | Iterator iter = ImageIO.getImageReadersByFormatName(formatName);
64 | return iter.hasNext();
65 | }
66 |
67 | public static double rgbToGrayscaleIntensity(int rgb) {
68 | Color c = new Color(rgb);
69 | return 0.2989 * c.getRed() + 0.5870 * c.getGreen() + 0.1140 * c.getBlue();
70 | }
71 |
72 | public static void parseRow(int[] rowRGB, PrintStream output) {
73 | output.print("\t");
74 | for (int i = rowRGB.length - 1; i >= 0; i -= 2) {
75 | int a = (255 - (int)Math.round(rgbToGrayscaleIntensity(rowRGB[i])));
76 | int b = (255 - (int)Math.round(rgbToGrayscaleIntensity(rowRGB[i - 1])));
77 | output.print(((a >> 4) & 0xFF) + "," + (((a << 4) | (b >> 8)) & 0xFF) + "," + (b & 0xFF) + ",");
78 | //System.out.print(
79 | // "GS_DUO(" + (255 - Math.round(rgbToGrayscaleIntensity(rowRGB[i]))) + "," +
80 | // (255 - Math.round(rgbToGrayscaleIntensity(rowRGB[i - 1]))) + "),");
81 | }
82 | output.println();
83 | }
84 |
85 |
86 | }
--------------------------------------------------------------------------------
/examples/BasicAnimations/Arduino.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sparkfun/SparkFun_TLC5940_Arduino_Library/df219716b7b08d252adabeb9474a56f7421e0ad4/examples/BasicAnimations/Arduino.png
--------------------------------------------------------------------------------
/examples/BasicAnimations/BasicAnimations.pde:
--------------------------------------------------------------------------------
1 | /*
2 | Writes "Ardunio" with Persistance of Vision (POV) with 16 LEDs (output 0
3 | is on bottom, output 15 is top). The animation below doesn't work with
4 | more than 1 TLC.
5 |
6 | I generated the animation with the included java code:
7 | /hardware/libraries/Tlc5940/examples/BasicAnimations
8 |
9 | To use the code, run
10 | java AnimationCreator
11 | in the folder above and it will parse all images in the folder to
12 | .h files. For best results use images that are 16 pixels high.
13 |
14 | See the BasicUse example for hardware setup.
15 |
16 | Alex Leone , 2009-02-03 */
17 |
18 | #include "SparkFun_Tlc5940.h"
19 | #include "tlc_animations.h"
20 | #include "ani_arduino.h"
21 |
22 | void setup()
23 | {
24 | Tlc.init();
25 | }
26 |
27 | void loop()
28 | {
29 | // checks to see if the animation is finished playing
30 | if (!tlc_onUpdateFinished) {
31 |
32 | delay(100);
33 |
34 | /*
35 | void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames,
36 | uint16_t periodsPerFrame);
37 | periods per frame is PWM periods, 1.024ms per frame (0 is valid - this
38 | will play the animation as fast as possible).
39 |
40 | Plays an animation in the "background".
41 | Don't call Tlc.update() while this is running.
42 | You can check if this is done with !tlc_onUpdateFinished */
43 | tlc_playAnimation(ani_arduino, ANI_ARDUINO_FRAMES, 3);
44 |
45 |
46 | // If you don't want to do anything until it's finished, use:
47 | // while (!tlc_onUpdateFinished);
48 |
49 | }
50 |
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/examples/BasicAnimations/ani_arduino.h:
--------------------------------------------------------------------------------
1 | #define ANI_ARDUINO_FRAMES 80
2 | uint8_t ani_arduino[NUM_TLCS * 24 * ANI_ARDUINO_FRAMES] PROGMEM = {
3 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,6,176,206,
4 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,65,10,64,247,15,240,255,
5 | 0,0,0,0,0,0,0,0,0,0,0,0,1,160,122,13,192,255,15,240,254,11,192,89,
6 | 0,0,0,0,0,0,0,0,4,4,240,179,15,192,255,15,240,255,8,32,33,0,0,0,
7 | 0,0,0,0,0,37,8,128,231,15,240,255,15,144,169,15,240,255,0,0,0,0,0,0,
8 | 0,0,94,12,16,255,15,240,255,13,64,113,1,48,0,15,240,255,0,0,0,0,0,0,
9 | 0,0,255,15,240,243,9,192,56,0,0,0,0,0,0,15,240,255,0,0,0,0,0,0,
10 | 0,0,255,15,240,243,9,208,57,0,0,0,0,0,0,15,240,255,0,0,0,0,0,0,
11 | 0,0,93,12,0,255,15,240,255,13,80,114,1,64,0,15,240,255,0,0,0,0,0,0,
12 | 0,0,0,0,0,36,8,112,230,15,240,255,15,144,170,15,240,255,0,0,0,0,0,0,
13 | 0,0,0,0,0,0,0,0,4,4,224,178,15,192,255,15,240,255,8,32,32,0,0,0,
14 | 0,0,0,0,0,0,0,0,0,0,0,0,1,144,121,13,176,255,15,240,254,11,160,86,
15 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,10,48,246,15,240,255,
16 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,6,160,206,
17 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
18 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
19 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
20 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
21 | 0,0,0,0,0,0,0,0,2,9,224,248,7,32,24,0,16,0,0,0,0,0,0,0,
22 | 0,0,0,0,0,0,0,0,109,15,240,115,0,0,0,0,0,0,0,0,0,0,0,0,
23 | 0,0,0,0,0,0,0,0,208,15,240,25,0,0,0,0,0,0,0,0,0,0,0,0,
24 | 0,0,0,0,0,0,0,0,248,15,240,1,0,0,0,0,0,0,0,0,0,0,0,0,
25 | 0,0,0,0,0,0,0,0,253,15,240,0,0,0,0,0,0,0,0,0,0,0,0,0,
26 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
27 | 0,0,0,0,0,0,0,0,0,0,16,90,11,176,237,15,192,237,11,176,90,0,16,0,
28 | 0,0,0,0,0,0,0,0,6,11,0,255,15,240,255,15,240,255,15,240,255,11,16,6,
29 | 0,0,0,0,0,0,0,0,125,15,240,247,7,48,26,0,48,26,7,16,246,15,240,126,
30 | 0,0,0,0,0,0,0,0,221,15,240,100,0,0,0,0,0,0,0,0,98,15,240,222,
31 | 0,0,0,0,0,0,0,0,250,15,240,14,0,0,0,0,0,0,0,0,13,15,240,249,
32 | 0,0,0,0,0,0,0,0,226,15,240,14,0,0,0,0,0,0,0,0,13,15,240,223,
33 | 0,0,0,0,0,0,0,0,130,15,240,103,0,0,0,0,0,0,0,0,100,15,240,131,
34 | 0,0,0,0,0,0,0,0,5,10,112,248,7,96,27,0,64,27,7,64,247,10,112,6,
35 | 15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
36 | 15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
37 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
38 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
40 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
41 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,253,14,144,173,3,32,0,
42 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,144,57,
43 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,2,224,201,15,240,186,
44 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,46,15,240,242,
45 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,15,240,246,
46 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,23,15,240,206,
47 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,111,15,240,102,
48 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13,6,32,246,9,80,0,
49 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
50 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
51 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
52 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
53 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
54 | 15,240,255,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
55 | 15,240,255,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
56 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
57 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
58 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
59 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
60 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
61 | 0,0,0,0,0,0,0,0,255,15,240,255,15,240,255,15,240,255,15,240,255,15,240,255,
62 | 0,0,0,0,0,0,0,0,0,9,64,246,6,48,13,0,0,0,0,0,0,0,0,0,
63 | 0,0,0,0,0,0,0,0,100,15,240,111,0,0,0,0,0,0,0,0,0,0,0,0,
64 | 0,0,0,0,0,0,0,0,208,15,240,24,0,0,0,0,0,0,0,0,0,0,0,0,
65 | 0,0,0,0,0,0,0,0,250,15,240,4,0,0,0,0,0,0,0,0,0,0,0,0,
66 | 0,0,0,0,0,0,0,0,241,15,240,47,0,0,0,0,0,0,0,0,0,0,0,0,
67 | 0,0,0,0,0,0,0,0,186,15,240,202,2,240,3,0,0,0,0,0,0,0,0,0,
68 | 0,0,0,0,0,0,0,0,57,15,144,255,15,240,255,15,240,255,15,240,255,15,240,255,
69 | 0,0,0,0,0,0,0,0,0,3,32,173,14,144,253,15,240,255,15,240,255,15,240,255,
70 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
71 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
72 | 0,0,0,0,0,0,0,0,0,0,0,73,11,80,235,15,176,235,11,80,74,0,0,0,
73 | 0,0,0,0,0,0,0,0,0,8,80,255,15,240,255,15,240,255,15,240,255,8,144,0,
74 | 0,0,0,0,0,0,0,0,72,15,240,254,8,128,31,0,64,31,8,128,254,15,240,74,
75 | 0,0,0,0,0,0,0,0,179,15,240,137,0,0,0,0,0,0,0,0,136,15,240,181,
76 | 0,0,0,0,0,0,0,0,234,15,240,32,0,0,0,0,0,0,0,0,31,15,240,235,
77 | 0,0,0,0,0,0,0,0,251,15,240,5,0,0,0,0,0,0,0,0,4,15,240,251,
78 | 0,0,0,0,0,0,0,0,234,15,240,33,0,0,0,0,0,0,0,0,32,15,240,235,
79 | 0,0,0,0,0,0,0,0,179,15,240,142,0,0,0,0,0,0,0,0,138,15,240,180,
80 | 0,0,0,0,0,0,0,0,69,15,240,255,8,224,33,0,80,32,8,176,254,15,240,72,
81 | 0,0,0,0,0,0,0,0,0,8,16,255,15,240,255,15,240,255,15,240,255,8,80,0,
82 | 0,0,0,0,0,0,0,0,0,0,0,70,11,48,234,15,176,234,11,48,72,0,0,0,
83 | };
84 |
85 |
--------------------------------------------------------------------------------
/examples/BasicUse/BasicUse.pde:
--------------------------------------------------------------------------------
1 | /*
2 | Basic Pin setup:
3 | ------------ ---u----
4 | ARDUINO 13|-> SCLK (pin 25) OUT1 |1 28| OUT channel 0
5 | 12| OUT2 |2 27|-> GND (VPRG)
6 | 11|-> SIN (pin 26) OUT3 |3 26|-> SIN (pin 11)
7 | 10|-> BLANK (pin 23) OUT4 |4 25|-> SCLK (pin 13)
8 | 9|-> XLAT (pin 24) . |5 24|-> XLAT (pin 9)
9 | 8| . |6 23|-> BLANK (pin 10)
10 | 7| . |7 22|-> GND
11 | 6| . |8 21|-> VCC (+5V)
12 | 5| . |9 20|-> 2K Resistor -> GND
13 | 4| . |10 19|-> +5V (DCPRG)
14 | 3|-> GSCLK (pin 18) . |11 18|-> GSCLK (pin 3)
15 | 2| . |12 17|-> SOUT
16 | 1| . |13 16|-> XERR
17 | 0| OUT14|14 15| OUT channel 15
18 | ------------ --------
19 |
20 | - Put the longer leg (anode) of the LEDs in the +5V and the shorter leg
21 | (cathode) in OUT(0-15).
22 | - +5V from Arduino -> TLC pin 21 and 19 (VCC and DCPRG)
23 | - GND from Arduino -> TLC pin 22 and 27 (GND and VPRG)
24 | - digital 3 -> TLC pin 18 (GSCLK)
25 | - digital 9 -> TLC pin 24 (XLAT)
26 | - digital 10 -> TLC pin 23 (BLANK)
27 | - digital 11 -> TLC pin 26 (SIN)
28 | - digital 13 -> TLC pin 25 (SCLK)
29 | - The 2K resistor between TLC pin 20 and GND will let ~20mA through each
30 | LED. To be precise, it's I = 39.06 / R (in ohms). This doesn't depend
31 | on the LED driving voltage.
32 | - (Optional): put a pull-up resistor (~10k) between +5V and BLANK so that
33 | all the LEDs will turn off when the Arduino is reset.
34 |
35 | If you are daisy-chaining more than one TLC, connect the SOUT of the first
36 | TLC to the SIN of the next. All the other pins should just be connected
37 | together:
38 | BLANK on Arduino -> BLANK of TLC1 -> BLANK of TLC2 -> ...
39 | XLAT on Arduino -> XLAT of TLC1 -> XLAT of TLC2 -> ...
40 | The one exception is that each TLC needs it's own resistor between pin 20
41 | and GND.
42 |
43 | This library uses the PWM output ability of digital pins 3, 9, 10, and 11.
44 | Do not use analogWrite(...) on these pins.
45 |
46 | This sketch does the Knight Rider strobe across a line of LEDs.
47 |
48 | Alex Leone , 2009-02-03 */
49 |
50 | #include "SparkFun_Tlc5940.h"
51 |
52 | void setup()
53 | {
54 | /* Call Tlc.init() to setup the tlc.
55 | You can optionally pass an initial PWM value (0 - 4095) for all channels.*/
56 | Tlc.init();
57 | }
58 |
59 | /* This loop will create a Knight Rider-like effect if you have LEDs plugged
60 | into all the TLC outputs. NUM_TLCS is defined in "tlc_config.h" in the
61 | library folder. After editing tlc_config.h for your setup, delete the
62 | Tlc5940.o file to save the changes. */
63 |
64 | void loop()
65 | {
66 | int direction = 1;
67 | for (int channel = 0; channel < NUM_TLCS * 16; channel += direction) {
68 |
69 | /* Tlc.clear() sets all the grayscale values to zero, but does not send
70 | them to the TLCs. To actually send the data, call Tlc.update() */
71 | Tlc.clear();
72 |
73 | /* Tlc.set(channel (0-15), value (0-4095)) sets the grayscale value for
74 | one channel (15 is OUT15 on the first TLC, if multiple TLCs are daisy-
75 | chained, then channel = 16 would be OUT0 of the second TLC, etc.).
76 |
77 | value goes from off (0) to always on (4095).
78 |
79 | Like Tlc.clear(), this function only sets up the data, Tlc.update()
80 | will send the data. */
81 | if (channel == 0) {
82 | direction = 1;
83 | } else {
84 | Tlc.set(channel - 1, 1000);
85 | }
86 | Tlc.set(channel, 4095);
87 | if (channel != NUM_TLCS * 16 - 1) {
88 | Tlc.set(channel + 1, 1000);
89 | } else {
90 | direction = -1;
91 | }
92 |
93 | /* Tlc.update() sends the data to the TLCs. This is when the LEDs will
94 | actually change. */
95 | Tlc.update();
96 |
97 | delay(75);
98 | }
99 |
100 | }
101 |
102 |
--------------------------------------------------------------------------------
/examples/CircularLightBuffer/CircularLightBuffer.pde:
--------------------------------------------------------------------------------
1 | /*
2 | A circular light buffer. If you manage to construct a circle of LEDs,
3 | definitely send in pictures. What this sketch does is take an analog
4 | reading off of analog pin 0 and add it to the current value of the last LED.
5 | If the resultant sum is greater than 4095, it turns the LED off,
6 | otherwise sets LED 0 to the value of the sum.
7 |
8 | If you ground pin 12, it will set LED 0 to zero.
9 |
10 | Then it shifts all the LED values up one (so LED 0 becomes LED 1) and sets
11 | LED 0 to the value shifted off the last LED (so if one LED is on, it will
12 | go in a circle forever).
13 |
14 | See the BasicUse example for hardware setup.
15 |
16 | Alex Leone , 2009-02-04 */
17 |
18 | #include "SparkFun_Tlc5940.h"
19 | #include "tlc_shifts.h"
20 |
21 | // which analog pin to use
22 | #define ANALOG_PIN 0
23 |
24 | // which pin to clear the LEDs with
25 | #define CLEAR_PIN 12
26 |
27 | // how many millis for one full revolution over all the LEDs
28 | #define SCOPE_PERIOD (2000 * NUM_TLCS)
29 | #define LED_PERIOD SCOPE_PERIOD / (NUM_TLCS * 16)
30 |
31 | void setup()
32 | {
33 | pinMode(CLEAR_PIN, INPUT);
34 | digitalWrite(CLEAR_PIN, HIGH); // enable pull-up
35 | Tlc.init();
36 | }
37 |
38 | void loop()
39 | {
40 | // shiftUp returns the value shifted off the last pin
41 | uint16_t sum = tlc_shiftUp() + analogRead(ANALOG_PIN) * 4;
42 | if (digitalRead(CLEAR_PIN) == LOW || sum > 4095)
43 | sum = 0;
44 | Tlc.set(0, sum);
45 | Tlc.update();
46 | delay(LED_PERIOD);
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/examples/FadeScope/FadeScope.pde:
--------------------------------------------------------------------------------
1 | /*
2 | A simple 1-d oscilliscope: scan all the channels, setting the PWM output
3 | value to 4x the analog pin 0 value (0 - 1024 * 4 = 4096). The value will
4 | fade to zero as the channels keep scanning.
5 |
6 | See the BasicUse example for hardware setup.
7 |
8 | Alex Leone , 2009-02-03 */
9 |
10 | #include "SparkFun_Tlc5940.h"
11 | #include "tlc_fades.h"
12 |
13 | // which analog pin to use
14 | #define ANALOG_PIN 0
15 |
16 | // how many millis to strobe over all the LEDs
17 | #define SCOPE_PERIOD (1000 * NUM_TLCS)
18 | #define LED_PERIOD SCOPE_PERIOD / (NUM_TLCS * 16)
19 |
20 | TLC_CHANNEL_TYPE channel;
21 |
22 | void setup()
23 | {
24 | Tlc.init();
25 | }
26 |
27 | void loop()
28 | {
29 | uint32_t lastMillis = millis();
30 | tlc_addFade(channel, // led channel
31 | analogRead(ANALOG_PIN) * 4, // start fade value (0-4095)
32 | 0, // end fade value (0-4095)
33 | lastMillis + 2, // start millis
34 | lastMillis + (uint16_t)SCOPE_PERIOD / 4 // end millis
35 | );
36 | if (channel++ == NUM_TLCS * 16) {
37 | channel = 0;
38 | }
39 | uint32_t currentMillis;
40 | do {
41 | currentMillis = millis();
42 | tlc_updateFades(currentMillis);
43 | } while (currentMillis - lastMillis <= LED_PERIOD);
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/examples/Fades/Fades.pde:
--------------------------------------------------------------------------------
1 | /*
2 | Fades a line down the channels, with max value and duration based on
3 | the voltage of analog pin 0.
4 | Try grounding analog 0: everything should turn off.
5 | Try putting +5V into analog 0: everything should turn on.
6 |
7 | See the BasicUse example for hardware setup.
8 |
9 | Alex Leone , 2009-02-03 */
10 |
11 | #include "SparkFun_Tlc5940.h"
12 | #include "tlc_fades.h"
13 |
14 | TLC_CHANNEL_TYPE channel;
15 |
16 | void setup()
17 | {
18 | Tlc.init();
19 | }
20 |
21 | void loop()
22 | {
23 | if (tlc_fadeBufferSize < TLC_FADE_BUFFER_LENGTH - 2) {
24 | if (!tlc_isFading(channel)) {
25 | uint16_t duration = analogRead(0) * 2;
26 | int maxValue = analogRead(0) * 2;
27 | uint32_t startMillis = millis() + 50;
28 | uint32_t endMillis = startMillis + duration;
29 | tlc_addFade(channel, 0, maxValue, startMillis, endMillis);
30 | tlc_addFade(channel, maxValue, 0, endMillis, endMillis + duration);
31 | }
32 | if (channel++ == NUM_TLCS * 16) {
33 | channel = 0;
34 | }
35 | }
36 | tlc_updateFades();
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/examples/Servos/Servos.pde:
--------------------------------------------------------------------------------
1 | /*
2 | This sketch sweeps a servo on channel 0.
3 |
4 | To connect a servo:
5 | 1. Put a 2k-5k pull-up resistor (R0 below; I've tried with 3.3k) between the
6 | servo control output pin and +5v.
7 | 2. Connect that same pin to the servo's control line like so
8 |
9 | servo data pin
10 | | _____
11 | OUTn ----+----[_____]---+5v
12 | R0
13 |
14 | Steve Pomeroy , 2009-01-20 */
15 |
16 | #include "SparkFun_Tlc5940.h"
17 | #include "tlc_servos.h"
18 |
19 | #define SERVO_CHANNEL 0
20 | #define DELAY_TIME 20
21 |
22 | void setup()
23 | {
24 | tlc_initServos(); // Note: this will drop the PWM freqency down to 50Hz.
25 | }
26 |
27 | void loop()
28 | {
29 | for (int angle = 0; angle < 180; angle++) {
30 | tlc_setServo(SERVO_CHANNEL, angle);
31 | Tlc.update();
32 | delay(DELAY_TIME);
33 | }
34 | for (int angle = 180; angle >= 0; angle--) {
35 | tlc_setServo(SERVO_CHANNEL, angle);
36 | Tlc.update();
37 | delay(DELAY_TIME);
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/examples/UsingProgmem/UsingProgmem.pde:
--------------------------------------------------------------------------------
1 | /*
2 | Setting grayscale from progmem to save RAM. If you want to play
3 | multiple "frames", (an animation), see the BasicAnimations Example.
4 |
5 | See the BasicUse example for hardware setup.
6 |
7 | Alex Leone , 2009-02-03 */
8 |
9 | #include "SparkFun_Tlc5940.h"
10 |
11 | // Extended functions (they start with tlc_...) require another include
12 | #include "tlc_progmem_utils.h"
13 |
14 | /*
15 | This is an array in program memory. Program memory is 16kB instead of
16 | 1024 bytes for regular variables in SRAM.
17 |
18 | The format for this array is
19 | GS_DUO(OUT15, OUT14), ... GS_DUO(OUT1, OUT0)
20 |
21 | If you have more than one TLC, the format is
22 | GS_DUO(TLC2.OUT15, TLC2.OUT14), ... GS_DUO(TLC2.OUT1, TLC2.OUT0),
23 | GS_DUO(TLC1.OUT15, TLC1.OUT14), ... GS_DUO(TLC1.OUT1, TLC1.OUT0)
24 |
25 | The pattern below will only work with 1 TLC. Copy + Paste the 4 lines
26 | inside the curly brackets for each additional TLC. */
27 | uint8_t gsArray1[NUM_TLCS * 24] PROGMEM = {
28 | GS_DUO((4095 * 16)/16, (4095 * 15)/16), GS_DUO((4095 * 14)/16, (4095 * 13)/16),
29 | GS_DUO((4095 * 12)/16, (4095 * 11)/16), GS_DUO((4095 * 10)/16, (4095 * 9)/16),
30 | GS_DUO((4095 * 8)/16, (4095 * 7)/16), GS_DUO((4095 * 6)/16, (4095 * 5)/16),
31 | GS_DUO((4095 * 4)/16, (4095 * 3)/16), GS_DUO((4095 * 2)/16, (4095 * 1)/16),
32 | };
33 |
34 | void setup()
35 | {
36 | Tlc.init();
37 | }
38 |
39 | void loop()
40 | {
41 | // Display the pattern (brightness ramp over the outputs)
42 | tlc_setGSfromProgmem(gsArray1);
43 | Tlc.update();
44 |
45 | // Fade each channel to zero
46 | for (TLC_CHANNEL_TYPE channel = 0; channel < NUM_TLCS * 16; channel++) {
47 | int16_t initialValue = Tlc.get(channel);
48 | while (initialValue > 0) {
49 | initialValue -= 5;
50 | if (initialValue < 0) {
51 | initialValue = 0;
52 | }
53 | Tlc.set(channel, initialValue);
54 |
55 | // wait until the data has been sent to the TLCs before continuing
56 | while (Tlc.update());
57 | }
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/extras/README.md:
--------------------------------------------------------------------------------
1 | Any extra documentation that should accompany the library.
2 |
3 | This directory is ignored by the Arduino Package manager, so do not place vital files in here!
--------------------------------------------------------------------------------
/extras/changelog.txt:
--------------------------------------------------------------------------------
1 | 2009-05-07
2 | - Added support for the Arduino Mega
3 |
4 | 2009-04-19
5 | - Bug fix in tlc_fades.h (incrementing a pointer after removing something
6 | from the fadeBuffer array). Also tlc_updateFades() will wait till after
7 | an update if it's just removed the last fade.
8 | - Updated the core function documentation.
9 |
10 | 2009-03-05
11 | - Fixed the missing pin definitions for the ATmega328p
12 |
13 | 2009-02-16
14 | - Added tlc_servos.h and example (thank you Steve Pomeroy)
15 | - Cleaned up some older documentation
16 | - Added trailing newlines to c, h, cpp, and pde files
17 |
18 | 2009-02-03
19 | - Added support for the Sanguino (ATmega xx4 series)
20 | - Added support for the ATmega 8
21 | - Moved the project to Google Code:
22 | http://code.google.com/p/tlc5940arduino/
23 | - Fixed a bug in tlc_fades.h: assignment of struct arrays
24 | - Cleaned up the whitespace in the library: 4 spaces instead of tabs
25 |
26 | 2009-01-25
27 | - Added tlc_fades.h
28 | - Added include "tlc_config.h" to Tlc5940.h so it's not required
29 | in the sketch
30 | - Added Tlc.setAll(value)
31 | - Changed a few for loops in Tlc5940.cpp: used *p++ instead of having
32 | p++ in the increment section of the for loop; changed to while loops
33 |
34 | 2008-11-26
35 | - Tlc.init() sets all channels to zero and updates.
36 | - Added TLC_PWM_PERIOD and TLC_GSCLK_PERIOD to tlc_config.h
37 | - Added TLC_CHANNEL_TYPE to tlc_config.h - Adds support for up to 4096 TLCs.
38 | (if TLC_CHANNEL_TYPE is uint16_t)
39 | - Changed the examples to use TLC_CHANNEL_TYPE
40 | - set DATA_TRANSFER_MODE default to TLC_SPI
41 |
42 | 2008-11-11
43 | - Added tlc_animations.h and examples
44 | - Fixed SPI mode - (don't use enums as constants
45 | "#if A == 1" doesn't work)
46 |
47 | 2008-10-31
48 | - Initial Release
49 |
--------------------------------------------------------------------------------
/extras/pinouts/ATmega_8.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_ATMEGA_8_H
20 | #define TLC_ATMEGA_8_H
21 |
22 | #if DATA_TRANSFER_MODE == TLC_SPI
23 | #warning SPI cannot be used on the ATmega8 because it interferes with timer2
24 | #warning setting DATA_TRANSFER_MODE to TLC_BITBANG
25 | #define DATA_TRANSFER_MODE TLC_BITBANG
26 | #endif
27 |
28 | /** \file
29 | SPI and timer pins for the ATmega8. Don't edit these. All
30 | changeable pins are defined in tlc_config.h */
31 |
32 | /** VPRG (Arduino digital pin 8) -> VPRG (TLC pin 27) */
33 | #define DEFAULT_VPRG_PIN PB0
34 | #define DEFAULT_VPRG_PORT PORTB
35 | #define DEFAULT_VPRG_DDR DDRB
36 |
37 | /** XERR (Arduino digital pin 12) -> XERR (TLC pin 16) */
38 | #define DEFAULT_XERR_PIN PB4
39 | #define DEFAULT_XERR_PORT PORTB
40 | #define DEFAULT_XERR_DDR DDRB
41 | #define DEFAULT_XERR_PINS PINB
42 |
43 | /** SIN (Arduino digital pin 7) -> SIN (TLC pin 26) */
44 | #define DEFAULT_BB_SIN_PIN PD7
45 | #define DEFAULT_BB_SIN_PORT PORTD
46 | #define DEFAULT_BB_SIN_DDR DDRD
47 | /** SCLK (Arduino digital pin 4) -> SCLK (TLC pin 25) */
48 | #define DEFAULT_BB_SCLK_PIN PD4
49 | #define DEFAULT_BB_SCLK_PORT PORTD
50 | #define DEFAULT_BB_SCLK_DDR DDRD
51 |
52 | /** MOSI (Arduino digital pin 11) -> SIN (TLC pin 26) */
53 | #define TLC_MOSI_PIN PB3
54 | #define TLC_MOSI_PORT PORTB
55 | #define TLC_MOSI_DDR DDRB
56 |
57 | /** SCK (Arduino digital pin 13) -> SCLK (TLC pin 25) */
58 | #define TLC_SCK_PIN PB5
59 | #define TLC_SCK_PORT PORTB
60 | #define TLC_SCK_DDR DDRB
61 |
62 | /** SS will be set to output as to not interfere with SPI master operation.
63 | If you have changed the pin-outs and the library doesn't seem to work
64 | or works intermittently, make sure this pin is set correctly. This pin
65 | will not be used by the library other than setting its direction to
66 | output. */
67 | #define TLC_SS_PIN PB2
68 | #define TLC_SS_DDR DDRB
69 |
70 | /** OC1A (Arduino digital pin 9) -> XLAT (TLC pin 24) */
71 | #define XLAT_PIN PB1
72 | #define XLAT_PORT PORTB
73 | #define XLAT_DDR DDRB
74 |
75 | /** OC1B (Arduino digital pin 10) -> BLANK (TLC pin 23) */
76 | #define BLANK_PIN PB2
77 | #define BLANK_PORT PORTB
78 | #define BLANK_DDR DDRB
79 |
80 | /** OC2B (Arduino digital pin 3) -> GSCLK (TLC pin 18) */
81 | #define GSCLK_PIN PD3
82 | #define GSCLK_PORT PORTD
83 | #define GSCLK_DDR DDRD
84 |
85 | #endif
86 |
87 |
--------------------------------------------------------------------------------
/extras/pinouts/ATmega_xx4.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_ATMEGA_XX8_H
20 | #define TLC_ATMEGA_XX8_H
21 |
22 | /** \file
23 | SPI and timer pins for the ATmega164/324/644. Don't edit these. All
24 | changeable pins are defined in tlc_config.h */
25 |
26 | /** VPRG (Sanguino digital pin 15) -> VPRG (TLC pin 27) */
27 | #define DEFAULT_VPRG_PIN PD7
28 | #define DEFAULT_VPRG_PORT PORTD
29 | #define DEFAULT_VPRG_DDR DDRD
30 |
31 | /** XERR (Sanguino digital pin 6) -> XERR (TLC pin 16) */
32 | #define DEFAULT_XERR_PIN PB6
33 | #define DEFAULT_XERR_PORT PORTB
34 | #define DEFAULT_XERR_DDR DDRB
35 | #define DEFAULT_XERR_PINS PINB
36 |
37 | /** SIN (Sanguino digital pin 5) -> SIN (TLC pin 26) */
38 | #define DEFAULT_BB_SIN_PIN PB5
39 | #define DEFAULT_BB_SIN_PORT PORTB
40 | #define DEFAULT_BB_SIN_DDR DDRB
41 | /** SCLK (Sanguino digital pin 7) -> SCLK (TLC pin 25) */
42 | #define DEFAULT_BB_SCLK_PIN PB7
43 | #define DEFAULT_BB_SCLK_PORT PORTB
44 | #define DEFAULT_BB_SCLK_DDR DDRB
45 |
46 | /** MOSI (Sanguino digital pin 5) -> SIN (TLC pin 26) */
47 | #define TLC_MOSI_PIN PB5
48 | #define TLC_MOSI_PORT PORTB
49 | #define TLC_MOSI_DDR DDRB
50 |
51 | /** SCK (Sanguino digital pin 7) -> SCLK (TLC pin 25) */
52 | #define TLC_SCK_PIN PB7
53 | #define TLC_SCK_PORT PORTB
54 | #define TLC_SCK_DDR DDRB
55 |
56 | /** SS will be set to output as to not interfere with SPI master operation.
57 | If you have changed the pin-outs and the library doesn't seem to work
58 | or works intermittently, make sure this pin is set correctly. This pin
59 | will not be used by the library other than setting its direction to
60 | output. */
61 | #define TLC_SS_PIN PB4
62 | #define TLC_SS_DDR DDRB
63 |
64 | /** OC1A (Sanguino digital pin 13) -> XLAT (TLC pin 24) */
65 | #define XLAT_PIN PD5
66 | #define XLAT_PORT PORTD
67 | #define XLAT_DDR DDRD
68 |
69 | /** OC1B (Sanguino digital pin 12) -> BLANK (TLC pin 23) */
70 | #define BLANK_PIN PD4
71 | #define BLANK_PORT PORTD
72 | #define BLANK_DDR DDRD
73 |
74 | /** OC2B (Sanguino digital pin 14) -> GSCLK (TLC pin 18) */
75 | #define GSCLK_PIN PD6
76 | #define GSCLK_PORT PORTD
77 | #define GSCLK_DDR DDRD
78 |
79 | #endif
80 |
81 |
--------------------------------------------------------------------------------
/extras/pinouts/ATmega_xx8.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_ATMEGA_XX8_H
20 | #define TLC_ATMEGA_XX8_H
21 |
22 | /** \file
23 | SPI and timer pins for the ATmega168/48/88. Don't edit these. All
24 | changeable pins are defined in tlc_config.h */
25 |
26 | /** VPRG (Arduino digital pin 8) -> VPRG (TLC pin 27) */
27 | #define DEFAULT_VPRG_PIN PB0
28 | #define DEFAULT_VPRG_PORT PORTB
29 | #define DEFAULT_VPRG_DDR DDRB
30 |
31 | /** XERR (Arduino digital pin 12) -> XERR (TLC pin 16) */
32 | #define DEFAULT_XERR_PIN PB4
33 | #define DEFAULT_XERR_PORT PORTB
34 | #define DEFAULT_XERR_DDR DDRB
35 | #define DEFAULT_XERR_PINS PINB
36 |
37 | /** SIN (Arduino digital pin 7) -> SIN (TLC pin 26) */
38 | #define DEFAULT_BB_SIN_PIN PD7
39 | #define DEFAULT_BB_SIN_PORT PORTD
40 | #define DEFAULT_BB_SIN_DDR DDRD
41 | /** SCLK (Arduino digital pin 4) -> SCLK (TLC pin 25) */
42 | #define DEFAULT_BB_SCLK_PIN PD4
43 | #define DEFAULT_BB_SCLK_PORT PORTD
44 | #define DEFAULT_BB_SCLK_DDR DDRD
45 |
46 | /** MOSI (Arduino digital pin 11) -> SIN (TLC pin 26) */
47 | #define TLC_MOSI_PIN PB3
48 | #define TLC_MOSI_PORT PORTB
49 | #define TLC_MOSI_DDR DDRB
50 |
51 | /** SCK (Arduino digital pin 13) -> SCLK (TLC pin 25) */
52 | #define TLC_SCK_PIN PB5
53 | #define TLC_SCK_PORT PORTB
54 | #define TLC_SCK_DDR DDRB
55 |
56 | /** SS will be set to output as to not interfere with SPI master operation.
57 | If you have changed the pin-outs and the library doesn't seem to work
58 | or works intermittently, make sure this pin is set correctly. This pin
59 | will not be used by the library other than setting its direction to
60 | output. */
61 | #define TLC_SS_PIN PB2
62 | #define TLC_SS_DDR DDRB
63 |
64 | /** OC1A (Arduino digital pin 9) -> XLAT (TLC pin 24) */
65 | #define XLAT_PIN PB1
66 | #define XLAT_PORT PORTB
67 | #define XLAT_DDR DDRB
68 |
69 | /** OC1B (Arduino digital pin 10) -> BLANK (TLC pin 23) */
70 | #define BLANK_PIN PB2
71 | #define BLANK_PORT PORTB
72 | #define BLANK_DDR DDRB
73 |
74 | /** OC2B (Arduino digital pin 3) -> GSCLK (TLC pin 18) */
75 | #define GSCLK_PIN PD3
76 | #define GSCLK_PORT PORTD
77 | #define GSCLK_DDR DDRD
78 |
79 | #endif
80 |
81 |
--------------------------------------------------------------------------------
/extras/pinouts/Arduino_Mega.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef ARDUINO_MEGA_H
20 | #define ARDUINO_MEGA_H
21 |
22 | /** \file
23 | SPI and timer pins for the Arduino Mega. Don't edit these. All
24 | changeable pins are defined in tlc_config.h */
25 |
26 | /** VPRG (Mega pin 50) -> VPRG (TLC pin 27) */
27 | #define DEFAULT_VPRG_PIN PB3
28 | #define DEFAULT_VPRG_PORT PORTB
29 | #define DEFAULT_VPRG_DDR DDRB
30 |
31 | /** XERR (Mega pin 10) -> XERR (TLC pin 16) */
32 | #define DEFAULT_XERR_PIN PB4
33 | #define DEFAULT_XERR_PORT PORTB
34 | #define DEFAULT_XERR_DDR DDRB
35 | #define DEFAULT_XERR_PINS PINB
36 |
37 | /** SIN (Mega pin 51) -> SIN (TLC pin 26) */
38 | #define DEFAULT_BB_SIN_PIN PB2
39 | #define DEFAULT_BB_SIN_PORT PORTB
40 | #define DEFAULT_BB_SIN_DDR DDRB
41 | /** SCLK (Mega pin 52) -> SCLK (TLC pin 25) */
42 | #define DEFAULT_BB_SCLK_PIN PB1
43 | #define DEFAULT_BB_SCLK_PORT PORTB
44 | #define DEFAULT_BB_SCLK_DDR DDRB
45 |
46 | /** MOSI (Mega pin 51) -> SIN (TLC pin 26) */
47 | #define TLC_MOSI_PIN PB2
48 | #define TLC_MOSI_PORT PORTB
49 | #define TLC_MOSI_DDR DDRB
50 |
51 | /** SCK (Mega pin 52) -> SCLK (TLC pin 25) */
52 | #define TLC_SCK_PIN PB1
53 | #define TLC_SCK_PORT PORTB
54 | #define TLC_SCK_DDR DDRB
55 |
56 | // SS (Mega pin 53)
57 | /** SS will be set to output as to not interfere with SPI master operation.
58 | If you have changed the pin-outs and the library doesn't seem to work
59 | or works intermittently, make sure this pin is set correctly. This pin
60 | will not be used by the library other than setting its direction to
61 | output. */
62 | #define TLC_SS_PIN PB0
63 | #define TLC_SS_DDR DDRB
64 |
65 | /** OC1A (Mega pin 11) -> XLAT (TLC pin 24) */
66 | #define XLAT_PIN PB5
67 | #define XLAT_PORT PORTB
68 | #define XLAT_DDR DDRB
69 |
70 | /** OC1B (Mega pin 12) -> BLANK (TLC pin 23) */
71 | #define BLANK_PIN PB6
72 | #define BLANK_PORT PORTB
73 | #define BLANK_DDR DDRB
74 |
75 | /** OC2B (Mega pin 9) -> GSCLK (TLC pin 18) */
76 | #define GSCLK_PIN PH6
77 | #define GSCLK_PORT PORTH
78 | #define GSCLK_DDR DDRH
79 |
80 | #endif
81 |
82 |
--------------------------------------------------------------------------------
/extras/pinouts/Teensy_xxU4.h:
--------------------------------------------------------------------------------
1 | #ifndef TLC_Teensy_xxU4_h
2 | #define TLC_Teensy_xxU4_h
3 |
4 | #if DATA_TRANSFER_MODE == TLC_BITBANG
5 | #error "If you want bitbang mode, insert pin defs here"
6 | #endif
7 |
8 | // MOSI (Teensy pin 2) -> SIN (TLC pin 26)
9 | #define TLC_MOSI_PIN 2
10 | #define TLC_MOSI_PORT PORTB
11 | #define TLC_MOSI_DDR DDRB
12 |
13 | // SCK (Teensy pin 1) -> SCLK (TLC pin 25)
14 | #define TLC_SCK_PIN 1
15 | #define TLC_SCK_PORT PORTB
16 | #define TLC_SCK_DDR DDRB
17 |
18 | // SS (Teensy pin 0)
19 | #define TLC_SS_PIN 0
20 | #define TLC_SS_DDR DDRB
21 |
22 | // OC1A (Teensy pin 14) -> XLAT (TLC pin 24)
23 | #define XLAT_PIN 5
24 | #define XLAT_PORT PORTB
25 | #define XLAT_DDR DDRB
26 |
27 | // OC1B (Teensy pin 15) -> BLANK (TLC pin 23)
28 | #define BLANK_PIN 6
29 | #define BLANK_PORT PORTB
30 | #define BLANK_DDR DDRB
31 |
32 | // OC3A (Teensy pin 9) -> GSCLK (TLC pin 18)
33 | #define GSCLK_PIN 6
34 | #define GSCLK_PORT PORTC
35 | #define GSCLK_DDR DDRC
36 | #define TLC_TIMER3_GSCLK 1
37 |
38 | #endif
39 |
40 |
--------------------------------------------------------------------------------
/extras/pinouts/Teensypp_xxx6.h:
--------------------------------------------------------------------------------
1 | #ifndef TLC_Teensypp_xxx6_H
2 | #define TLC_Teensypp_xxx6_H
3 |
4 | #if DATA_TRANSFER_MODE == TLC_BITBANG
5 | #error "If you want bitbang mode, insert pin defs here"
6 | #endif
7 |
8 | // MOSI (Teensy++ pin 22) -> SIN (TLC pin 26)
9 | #define TLC_MOSI_PIN 2
10 | #define TLC_MOSI_PORT PORTB
11 | #define TLC_MOSI_DDR DDRB
12 |
13 | // SCK (Teensy++ pin 21) -> SCLK (TLC pin 25)
14 | #define TLC_SCK_PIN 1
15 | #define TLC_SCK_PORT PORTB
16 | #define TLC_SCK_DDR DDRB
17 |
18 | // SS (Teensy++ pin 20)
19 | #define TLC_SS_PIN 0
20 | #define TLC_SS_DDR DDRB
21 |
22 | // OC1A (Teensy++ pin 25) -> XLAT (TLC pin 24)
23 | #define XLAT_PIN 5
24 | #define XLAT_PORT PORTB
25 | #define XLAT_DDR DDRB
26 |
27 | // OC1B (Teensy++ pin 26) -> BLANK (TLC pin 23)
28 | #define BLANK_PIN 6
29 | #define BLANK_PORT PORTB
30 | #define BLANK_DDR DDRB
31 |
32 | // OC2B (Teensy++ pin 1) -> GSCLK (TLC pin 18)
33 | #define GSCLK_PIN 1
34 | #define GSCLK_PORT PORTD
35 | #define GSCLK_DDR DDRD
36 |
37 | #endif
38 |
39 |
--------------------------------------------------------------------------------
/extras/pinouts/chip_includes.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_CHIP_INCLUDES_H
20 | #define TLC_CHIP_INCLUDES_H
21 |
22 | /** \file
23 | Includes the chip-specfic defaults and pin definitions. */
24 |
25 | #include
26 |
27 | #ifndef PB0
28 | #define PB0 PORTB0
29 | #define PB1 PORTB1
30 | #define PB2 PORTB2
31 | #define PB3 PORTB3
32 | #define PB4 PORTB4
33 | #define PB5 PORTB5
34 | #define PB6 PORTB6
35 | #define PB7 PORTB7
36 | #endif
37 | #ifndef PC0
38 | #define PC0 PORTC0
39 | #define PC1 PORTC1
40 | #define PC2 PORTC2
41 | #define PC3 PORTC3
42 | #define PC4 PORTC4
43 | #define PC5 PORTC5
44 | #define PC6 PORTC6
45 | #define PC7 PORTC7
46 | #endif
47 | #ifndef PD0
48 | #define PD0 PORTD0
49 | #define PD1 PORTD1
50 | #define PD2 PORTD2
51 | #define PD3 PORTD3
52 | #define PD4 PORTD4
53 | #define PD5 PORTD5
54 | #define PD6 PORTD6
55 | #define PD7 PORTD7
56 | #endif
57 | #ifndef PH0
58 | #define PH0 PORTH0
59 | #define PH1 PORTH1
60 | #define PH2 PORTH2
61 | #define PH3 PORTH3
62 | #define PH4 PORTH4
63 | #define PH5 PORTH5
64 | #define PH6 PORTH6
65 | #define PH7 PORTH7
66 | #endif
67 |
68 | /* Chip Specific Pinouts */
69 | #if defined (__AVR_ATmega168__) \
70 | || defined (__AVR_ATmega168P__) \
71 | || defined (__AVR_ATmega88P__) \
72 | || defined (__AVR_ATmega88__) \
73 | || defined (__AVR_ATmega48P__) \
74 | || defined (__AVR_ATmega48__) \
75 | || defined (__AVR_ATmega328P__)
76 |
77 | /* Diecimila / Duemilanove / almost everything */
78 | #include "ATmega_xx8.h"
79 |
80 | #elif defined (__AVR_ATmega8__)
81 |
82 | /* ATmega8 */
83 | #include "ATmega_8.h"
84 |
85 | #elif defined (__AVR_ATmega164P__) \
86 | || defined (__AVR_ATmega324P__) \
87 | || defined (__AVR_ATmega644__) \
88 | || defined (__AVR_ATmega644P__)
89 |
90 | /* Sanguino */
91 | #include "ATmega_xx4.h"
92 |
93 | #elif defined (__AVR_ATmega640__) \
94 | || defined (__AVR_ATmega1280__) \
95 | || defined (__AVR_ATmega1281__) \
96 | || defined (__AVR_ATmega2560__) \
97 | || defined (__AVR_ATmega2561__)
98 |
99 | /* Arduino Mega */
100 | #include "Arduino_Mega.h"
101 |
102 | #elif defined (__AVR_ATmega32U4__)
103 |
104 | /* Teensy 2.0 */
105 | #include "Teensy_xxU4.h"
106 |
107 | #elif defined (__AVR_AT90USB646__) \
108 | || defined (__AVR_AT90USB1286__)
109 |
110 | /* Teensy++ 2.0 */
111 | #include "Teensypp_xxx6.h"
112 |
113 | #else
114 | #error "Unknown Chip!"
115 | #endif
116 |
117 | #endif
118 |
119 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | #######################################
2 | # Syntax Coloring Map For TLC5940
3 | #######################################
4 |
5 | #######################################
6 | # Datatypes (KEYWORD1)
7 | #######################################
8 |
9 | Tlc5940 KEYWORD1
10 |
11 | #######################################
12 | # Methods and Functions (KEYWORD2)
13 | #######################################
14 |
15 | init KEYWORD2
16 | clear KEYWORD2
17 | update KEYWORD2
18 | set KEYWORD2
19 | get KEYWORD2
20 | setAll KEYWORD2
21 | setAllDC KEYWORD2
22 | readXERR KEYWORD2
23 | tlc_setGSfromProgmem KEYWORD2
24 | tlc_setDCfromProgmem KEYWORD2
25 | tlc_playAnimation KEYWORD2
26 | tlc_addFade KEYWORD2
27 | tlc_removeFade KEYWORD2
28 | tlc_shiftUp KEYWORD2
29 | tlc_shiftDown KEYWORD2
30 |
31 | #######################################
32 | # Instances (KEYWORD2)
33 | #######################################
34 |
35 | Tlc KEYWORD2
36 |
37 | #######################################
38 | # Constants (LITERAL1)
39 | #######################################
40 |
41 | NUM_TLCS LITERAL1
42 | tlc_needXLAT LITERAL1
43 | tlc_GSData LITERAL1
44 | tlc_onUpdateFinished LITERAL1
45 | TLC_FADE_BUFFER_LENGTH LITERAL1
46 | tlc_fadeBufferSize LITERAL1
47 |
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=SparkFun TLC5940
2 | version=1.1.1
3 | author=Alex Leone , SparkFun Electronics
4 | maintainer=SparkFun Electronics
5 | sentence=Library for the TLC5940 IC.
6 | paragraph=The TLC5940 gives the user 16 channel PWM control and can be daisy chained over the serial interface. This library works with the SparkFun LED Driver Breakout and the SparkFun PWM Shield.
7 | category=Signal Input/Output
8 | url=https://github.com/sparkfun/SparkFun_TLC5940_Arduino_Library
9 | architectures=avr
10 |
--------------------------------------------------------------------------------
/src/SparkFun_Tlc5940.cpp:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | /** \file
20 | Tlc5940 class functions. */
21 |
22 | #include
23 | #include
24 |
25 | #include "tlc_config.h"
26 | #include "SparkFun_Tlc5940.h"
27 |
28 | /** Pulses a pin - high then low. */
29 | #define pulse_pin(port, pin) port |= _BV(pin); port &= ~_BV(pin)
30 |
31 | /** This will be true (!= 0) if update was just called and the data has not
32 | been latched in yet. */
33 | volatile uint8_t tlc_needXLAT;
34 |
35 | /** Some of the extened library will need to be called after a successful
36 | update. */
37 | volatile void (*tlc_onUpdateFinished)(void);
38 |
39 | /** Packed grayscale data, 24 bytes (16 * 12 bits) per TLC.
40 |
41 | Format: Lets assume we have 2 TLCs, A and B, daisy-chained with the SOUT of
42 | A going into the SIN of B.
43 | - byte 0: upper 8 bits of B.15
44 | - byte 1: lower 4 bits of B.15 and upper 4 bits of B.14
45 | - byte 2: lower 8 bits of B.0
46 | - ...
47 | - byte 24: upper 8 bits of A.15
48 | - byte 25: lower 4 bits of A.15 and upper 4 bits of A.14
49 | - ...
50 | - byte 47: lower 8 bits of A.0
51 |
52 | \note Normally packing data like this is bad practice. But in this
53 | situation, shifting the data out is really fast because the format of
54 | the array is the same as the format of the TLC's serial interface. */
55 | uint8_t tlc_GSData[NUM_TLCS * 24];
56 |
57 | /** Don't add an extra SCLK pulse after switching from dot-correction mode. */
58 | static uint8_t firstGSInput;
59 |
60 | /** Interrupt called after an XLAT pulse to prevent more XLAT pulses. */
61 | ISR(TIMER1_OVF_vect)
62 | {
63 | disable_XLAT_pulses();
64 | clear_XLAT_interrupt();
65 | tlc_needXLAT = 0;
66 | if (tlc_onUpdateFinished) {
67 | sei();
68 | tlc_onUpdateFinished();
69 | }
70 | }
71 |
72 | /** \defgroup ReqVPRG_ENABLED Functions that Require VPRG_ENABLED
73 | Functions that require VPRG_ENABLED == 1.
74 | You can enable VPRG by changing
75 | \code #define VPRG_ENABLED 0 \endcode to
76 | \code #define VPRG_ENABLED 1 \endcode in tlc_config.h
77 |
78 | You will also have to connect Arduino digital pin 6 to TLC pin 27. (The
79 | pin to be used can be changed in tlc_config.h). If VPRG is not enabled,
80 | the TLC pin should grounded (remember to unconnect TLC pin 27 from GND
81 | if you do enable VPRG). */
82 | /* @{ */ /* @} */
83 |
84 | /** \defgroup CoreFunctions Core Libary Functions
85 | These function are all prefixed with "Tlc." */
86 | /* @{ */
87 |
88 | /** Pin i/o and Timer setup. The grayscale register will be reset to all
89 | zeros, or whatever initialValue is set to and the Timers will start.
90 | \param initialValue = 0, optional parameter specifing the inital startup
91 | value */
92 | void Tlc5940::init(uint16_t initialValue)
93 | {
94 | /* Pin Setup */
95 | XLAT_DDR |= _BV(XLAT_PIN);
96 | BLANK_DDR |= _BV(BLANK_PIN);
97 | GSCLK_DDR |= _BV(GSCLK_PIN);
98 | #if VPRG_ENABLED
99 | VPRG_DDR |= _BV(VPRG_PIN);
100 | VPRG_PORT &= ~_BV(VPRG_PIN); // grayscale mode (VPRG low)
101 | #endif
102 | #if XERR_ENABLED
103 | XERR_DDR &= ~_BV(XERR_PIN); // XERR as input
104 | XERR_PORT |= _BV(XERR_PIN); // enable pull-up resistor
105 | #endif
106 | BLANK_PORT |= _BV(BLANK_PIN); // leave blank high (until the timers start)
107 |
108 | tlc_shift8_init();
109 |
110 | setAll(initialValue);
111 | update();
112 | disable_XLAT_pulses();
113 | clear_XLAT_interrupt();
114 | tlc_needXLAT = 0;
115 | pulse_pin(XLAT_PORT, XLAT_PIN);
116 |
117 |
118 | /* Timer Setup */
119 |
120 | /* Timer 1 - BLANK / XLAT */
121 | TCCR1A = _BV(COM1B1); // non inverting, output on OC1B, BLANK
122 | TCCR1B = _BV(WGM13); // Phase/freq correct PWM, ICR1 top
123 | OCR1A = 1; // duty factor on OC1A, XLAT is inside BLANK
124 | OCR1B = 2; // duty factor on BLANK (larger than OCR1A (XLAT))
125 | ICR1 = TLC_PWM_PERIOD; // see tlc_config.h
126 |
127 | /* Timer 2 - GSCLK */
128 | #if defined(TLC_ATMEGA_8_H)
129 | TCCR2 = _BV(COM20) // set on BOTTOM, clear on OCR2A (non-inverting),
130 | | _BV(WGM21); // output on OC2B, CTC mode with OCR2 top
131 | OCR2 = TLC_GSCLK_PERIOD / 2; // see tlc_config.h
132 | TCCR2 |= _BV(CS20); // no prescale, (start pwm output)
133 | #elif defined(TLC_TIMER3_GSCLK)
134 | TCCR3A = _BV(COM3A1) // set on BOTTOM, clear on OCR3A (non-inverting),
135 | // output on OC3A
136 | | _BV(WGM31); // Fast pwm with ICR3 top
137 | OCR3A = 0; // duty factor (as short a pulse as possible)
138 | ICR3 = TLC_GSCLK_PERIOD; // see tlc_config.h
139 | TCCR3B = _BV(CS30) // no prescale, (start pwm output)
140 | | _BV(WGM32) // Fast pwm with ICR3 top
141 | | _BV(WGM33); // Fast pwm with ICR3 top
142 | #else
143 | TCCR2A = _BV(COM2B1) // set on BOTTOM, clear on OCR2A (non-inverting),
144 | // output on OC2B
145 | | _BV(WGM21) // Fast pwm with OCR2A top
146 | | _BV(WGM20); // Fast pwm with OCR2A top
147 | TCCR2B = _BV(WGM22); // Fast pwm with OCR2A top
148 | OCR2B = 0; // duty factor (as short a pulse as possible)
149 | OCR2A = TLC_GSCLK_PERIOD; // see tlc_config.h
150 | TCCR2B |= _BV(CS20); // no prescale, (start pwm output)
151 | #endif
152 | TCCR1B |= _BV(CS10); // no prescale, (start pwm output)
153 | update();
154 | }
155 |
156 | /** Clears the grayscale data array, #tlc_GSData, but does not shift in any
157 | data. This call should be followed by update() if you are turning off
158 | all the outputs. */
159 | void Tlc5940::clear(void)
160 | {
161 | setAll(0);
162 | }
163 |
164 | /** Shifts in the data from the grayscale data array, #tlc_GSData.
165 | If data has already been shifted in this grayscale cycle, another call to
166 | update() will immediately return 1 without shifting in the new data. To
167 | ensure that a call to update() does shift in new data, use
168 | \code while(Tlc.update()); \endcode
169 | or
170 | \code while(tlc_needXLAT); \endcode
171 | \returns 1 if there is data waiting to be latched, 0 if data was
172 | successfully shifted in */
173 | uint8_t Tlc5940::update(void)
174 | {
175 | if (tlc_needXLAT) {
176 | return 1;
177 | }
178 | disable_XLAT_pulses();
179 | if (firstGSInput) {
180 | // adds an extra SCLK pulse unless we've just set dot-correction data
181 | firstGSInput = 0;
182 | } else {
183 | pulse_pin(SCLK_PORT, SCLK_PIN);
184 | }
185 | uint8_t *p = tlc_GSData;
186 | while (p < tlc_GSData + NUM_TLCS * 24) {
187 | tlc_shift8(*p++);
188 | tlc_shift8(*p++);
189 | tlc_shift8(*p++);
190 | }
191 | tlc_needXLAT = 1;
192 | enable_XLAT_pulses();
193 | set_XLAT_interrupt();
194 | return 0;
195 | }
196 |
197 | /** Sets channel to value in the grayscale data array, #tlc_GSData.
198 | \param channel (0 to #NUM_TLCS * 16 - 1). OUT0 of the first TLC is
199 | channel 0, OUT0 of the next TLC is channel 16, etc.
200 | \param value (0-4095). The grayscale value, 4095 is maximum.
201 | \see get */
202 | void Tlc5940::set(TLC_CHANNEL_TYPE channel, uint16_t value)
203 | {
204 | TLC_CHANNEL_TYPE index8 = (NUM_TLCS * 16 - 1) - channel;
205 | uint8_t *index12p = tlc_GSData + ((((uint16_t)index8) * 3) >> 1);
206 | if (index8 & 1) { // starts in the middle
207 | // first 4 bits intact | 4 top bits of value
208 | *index12p = (*index12p & 0xF0) | (value >> 8);
209 | // 8 lower bits of value
210 | *(++index12p) = value & 0xFF;
211 | } else { // starts clean
212 | // 8 upper bits of value
213 | *(index12p++) = value >> 4;
214 | // 4 lower bits of value | last 4 bits intact
215 | *index12p = ((uint8_t)(value << 4)) | (*index12p & 0xF);
216 | }
217 | }
218 |
219 | /** Gets the current grayscale value for a channel
220 | \param channel (0 to #NUM_TLCS * 16 - 1). OUT0 of the first TLC is
221 | channel 0, OUT0 of the next TLC is channel 16, etc.
222 | \returns current grayscale value (0 - 4095) for channel
223 | \see set */
224 | uint16_t Tlc5940::get(TLC_CHANNEL_TYPE channel)
225 | {
226 | TLC_CHANNEL_TYPE index8 = (NUM_TLCS * 16 - 1) - channel;
227 | uint8_t *index12p = tlc_GSData + ((((uint16_t)index8) * 3) >> 1);
228 | return (index8 & 1)? // starts in the middle
229 | (((uint16_t)(*index12p & 15)) << 8) | // upper 4 bits
230 | *(index12p + 1) // lower 8 bits
231 | : // starts clean
232 | (((uint16_t)(*index12p)) << 4) | // upper 8 bits
233 | ((*(index12p + 1) & 0xF0) >> 4); // lower 4 bits
234 | // that's probably the ugliest ternary operator I've ever created.
235 | }
236 |
237 | /** Sets all channels to value.
238 | \param value grayscale value (0 - 4095) */
239 | void Tlc5940::setAll(uint16_t value)
240 | {
241 | uint8_t firstByte = value >> 4;
242 | uint8_t secondByte = (value << 4) | (value >> 8);
243 | uint8_t *p = tlc_GSData;
244 | while (p < tlc_GSData + NUM_TLCS * 24) {
245 | *p++ = firstByte;
246 | *p++ = secondByte;
247 | *p++ = (uint8_t)value;
248 | }
249 | }
250 |
251 | #if VPRG_ENABLED
252 |
253 | /** \addtogroup ReqVPRG_ENABLED
254 | From the \ref CoreFunctions "Core Functions":
255 | - \link Tlc5940::setAllDC Tlc.setAllDC(uint8_t value(0-63)) \endlink - sets
256 | all the dot correction data to value */
257 | /* @{ */
258 |
259 | /** Sets the dot correction for all channels to value. The dot correction
260 | value correspondes to maximum output current by
261 | \f$\displaystyle I_{OUT_n} = I_{max} \times \frac{DCn}{63} \f$
262 | where
263 | - \f$\displaystyle I_{max} = \frac{1.24V}{R_{IREF}} \times 31.5 =
264 | \frac{39.06}{R_{IREF}} \f$
265 | - DCn is the dot correction value for channel n
266 | \param value (0-63) */
267 | void Tlc5940::setAllDC(uint8_t value)
268 | {
269 | tlc_dcModeStart();
270 |
271 | uint8_t firstByte = value << 2 | value >> 4;
272 | uint8_t secondByte = value << 4 | value >> 2;
273 | uint8_t thirdByte = value << 6 | value;
274 |
275 | for (TLC_CHANNEL_TYPE i = 0; i < NUM_TLCS * 12; i += 3) {
276 | tlc_shift8(firstByte);
277 | tlc_shift8(secondByte);
278 | tlc_shift8(thirdByte);
279 | }
280 | pulse_pin(XLAT_PORT, XLAT_PIN);
281 |
282 | tlc_dcModeStop();
283 | }
284 |
285 | /* @} */
286 |
287 | #endif
288 |
289 | #if XERR_ENABLED
290 |
291 | /** Checks for shorted/broken LEDs reported by any of the TLCs.
292 | \returns 1 if a TLC is reporting an error, 0 otherwise. */
293 | uint8_t Tlc5940::readXERR(void)
294 | {
295 | return ((XERR_PINS & _BV(XERR_PIN)) == 0);
296 | }
297 |
298 | #endif
299 |
300 | /* @} */
301 |
302 | #if DATA_TRANSFER_MODE == TLC_BITBANG
303 |
304 | /** Sets all the bit-bang pins to output */
305 | void tlc_shift8_init(void)
306 | {
307 | SIN_DDR |= _BV(SIN_PIN); // SIN as output
308 | SCLK_DDR |= _BV(SCLK_PIN); // SCLK as output
309 | SCLK_PORT &= ~_BV(SCLK_PIN);
310 | }
311 |
312 | /** Shifts a byte out, MSB first */
313 | void tlc_shift8(uint8_t byte)
314 | {
315 | for (uint8_t bit = 0x80; bit; bit >>= 1) {
316 | if (bit & byte) {
317 | SIN_PORT |= _BV(SIN_PIN);
318 | } else {
319 | SIN_PORT &= ~_BV(SIN_PIN);
320 | }
321 | pulse_pin(SCLK_PORT, SCLK_PIN);
322 | }
323 | }
324 |
325 | #elif DATA_TRANSFER_MODE == TLC_SPI
326 |
327 | /** Initializes the SPI module to double speed (f_osc / 2) */
328 | void tlc_shift8_init(void)
329 | {
330 | SIN_DDR |= _BV(SIN_PIN); // SPI MOSI as output
331 | SCLK_DDR |= _BV(SCLK_PIN); // SPI SCK as output
332 | TLC_SS_DDR |= _BV(TLC_SS_PIN); // SPI SS as output
333 |
334 | SCLK_PORT &= ~_BV(SCLK_PIN);
335 |
336 | SPSR = _BV(SPI2X); // double speed (f_osc / 2)
337 | SPCR = _BV(SPE) // enable SPI
338 | | _BV(MSTR); // master mode
339 | }
340 |
341 | /** Shifts out a byte, MSB first */
342 | void tlc_shift8(uint8_t byte)
343 | {
344 | SPDR = byte; // starts transmission
345 | while (!(SPSR & _BV(SPIF)))
346 | ; // wait for transmission complete
347 | }
348 |
349 | #endif
350 |
351 | #if VPRG_ENABLED
352 |
353 | /** Switches to dot correction mode and clears any waiting grayscale latches.*/
354 | void tlc_dcModeStart(void)
355 | {
356 | disable_XLAT_pulses(); // ensure that no latches happen
357 | clear_XLAT_interrupt(); // (in case this was called right after update)
358 | tlc_needXLAT = 0;
359 | VPRG_PORT |= _BV(VPRG_PIN); // dot correction mode
360 | }
361 |
362 | /** Switches back to grayscale mode. */
363 | void tlc_dcModeStop(void)
364 | {
365 | VPRG_PORT &= ~_BV(VPRG_PIN); // back to grayscale mode
366 | firstGSInput = 1;
367 | }
368 |
369 | #endif
370 |
371 | /** Preinstantiated Tlc variable. */
372 | Tlc5940 Tlc;
373 |
374 | /** \defgroup ExtendedFunctions Extended Library Functions
375 | These functions require an include statement at the top of the sketch. */
376 | /* @{ */ /* @} */
377 |
378 | /** \mainpage
379 | The Texas Instruments TLC5940
380 | is a 16-channel, constant-current sink LED driver. Each channel has
381 | an individually adjustable 4096-step grayscale PWM brightness control and
382 | a 64-step, constant-current sink (no LED resistors needed!). This chip
383 | is a current sink, so be sure to use common anode RGB LEDs.
384 |
385 | Check the tlc5940arduino
386 | project on Google Code for updates. To install, unzip the "Tlc5940"
387 | folder to <Arduino Folder>/hardware/libraries/
388 |
389 |
390 |
391 | \section hardwaresetup Hardware Setup
392 | The basic hardware setup is explained at the top of the Examples. A good
393 | place to start would be the BasicUse Example. (The examples are in
394 | File->Sketchbook->Examples->Library-Tlc5940).
395 |
396 | All the options for the library are located in tlc_config.h, including
397 | #NUM_TLCS, what pins to use, and the PWM period. After changing
398 | tlc_config.h, be sure to delete the Tlc5940.o file in the library folder
399 | to save the changes.
400 |
401 |
402 |
403 | \section libref Library Reference
404 | \ref CoreFunctions "Core Functions" (see the BasicUse Example and Tlc5940):
405 | - \link Tlc5940::init Tlc.init(int initialValue (0-4095))\endlink - Call this is
406 | to setup the timers before using any other Tlc functions.
407 | initialValue defaults to zero (all channels off).
408 | - \link Tlc5940::clear Tlc.clear()\endlink - Turns off all channels
409 | (Needs Tlc.update())
410 | - \link Tlc5940::set Tlc.set(uint8_t channel (0-(NUM_TLCS * 16 - 1)),
411 | int value (0-4095))\endlink - sets the grayscale data for channel.
412 | (Needs Tlc.update())
413 | - \link Tlc5940::setAll Tlc.setAll(int value(0-4095))\endlink - sets all
414 | channels to value. (Needs Tlc.update())
415 | - \link Tlc5940::get uint16_t Tlc.get(uint8_t channel)\endlink - returns
416 | the grayscale data for channel (see set).
417 | - \link Tlc5940::update Tlc.update()\endlink - Sends the changes from any
418 | Tlc.clear's, Tlc.set's, or Tlc.setAll's.
419 |
420 | \ref ExtendedFunctions "Extended Functions". These require an include
421 | statement at the top of the sketch to use.
422 |
423 | \ref ReqVPRG_ENABLED "Functions that require VPRG_ENABLED". These
424 | require VPRG_ENABLED == 1 in tlc_config.h
425 |
426 |
427 |
428 | \section expansion Expanding the Library
429 | Lets say we wanted to add a function like "tlc_goCrazy(...)". The first
430 | thing to do is to create a source file in the library folder,
431 | "tlc_my_crazy_functions.h".
432 | A template for this .h file is
433 | \code
434 | // Explination for my crazy function extension
435 |
436 | #ifndef TLC_MY_CRAZY_FUNCTIONS_H
437 | #define TLC_MY_CRAZY_FUNCTIONS_H
438 |
439 | #include "tlc_config.h"
440 | #include "Tlc5940.h"
441 |
442 | void tlc_goCrazy(void);
443 |
444 | void tlc_goCrazy(void)
445 | {
446 | uint16_t crazyFactor = 4000;
447 | Tlc.clear();
448 | for (uint8_t channel = 4; channel < 9; channel++) {
449 | Tlc.set(channel, crazyFactor);
450 | }
451 | Tlc.update();
452 | }
453 |
454 | #endif
455 | * \endcode
456 | * Now to use your library in a sketch, just add
457 | * \code
458 | #include "tlc_my_crazy_functions.h"
459 |
460 | // ...
461 |
462 | tlc_goCrazy();
463 | \endcode
464 | If you would like to share your extended functions for others to use,
465 | email me (acleone ~AT~ gmail.com) with the file and an example and I'll
466 | include them in the library.
467 |
468 |
469 |
470 | \section bugs Contact
471 | If you found a bug in the library, email me so I can fix it!
472 | My email is acleone ~AT~ gmail.com
473 |
474 |
475 |
476 | \section license License - GPLv3
477 | Copyright (c) 2009 by Alex Leone
478 |
479 | This file is part of the Arduino TLC5940 Library.
480 |
481 | The Arduino TLC5940 Library is free software: you can redistribute it
482 | and/or modify it under the terms of the GNU General Public License as
483 | published by the Free Software Foundation, either version 3 of the
484 | License, or (at your option) any later version.
485 |
486 | The Arduino TLC5940 Library is distributed in the hope that it will be
487 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
488 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
489 | GNU General Public License for more details.
490 |
491 | You should have received a copy of the GNU General Public License
492 | along with The Arduino TLC5940 Library. If not, see
493 | . */
494 |
495 |
--------------------------------------------------------------------------------
/src/SparkFun_Tlc5940.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef SPARKFUN_TLC5940_H
20 | #define SPARKFUN_TLC5940_H
21 |
22 | /** \file
23 | Tlc5940 library header file. */
24 |
25 | #include
26 | #include "tlc_config.h"
27 |
28 | #ifdef TLC_ATMEGA_8_H
29 |
30 | /** Enables the Timer1 Overflow interrupt, which will fire after an XLAT
31 | pulse */
32 | #define set_XLAT_interrupt() TIFR |= _BV(TOV1); TIMSK = _BV(TOIE1)
33 | /** Disables any Timer1 interrupts */
34 | #define clear_XLAT_interrupt() TIMSK = 0
35 |
36 | #else
37 |
38 | /** Enables the Timer1 Overflow interrupt, which will fire after an XLAT
39 | pulse */
40 | #define set_XLAT_interrupt() TIFR1 |= _BV(TOV1); TIMSK1 = _BV(TOIE1)
41 | /** Disables any Timer1 interrupts */
42 | #define clear_XLAT_interrupt() TIMSK1 = 0
43 |
44 | #endif
45 |
46 | /** Enables the output of XLAT pulses */
47 | #define enable_XLAT_pulses() TCCR1A = _BV(COM1A1) | _BV(COM1B1)
48 | /** Disables the output of XLAT pulses */
49 | #define disable_XLAT_pulses() TCCR1A = _BV(COM1B1)
50 |
51 | extern volatile uint8_t tlc_needXLAT;
52 | extern volatile void (*tlc_onUpdateFinished)(void);
53 | extern uint8_t tlc_GSData[NUM_TLCS * 24];
54 |
55 | /** The main Tlc5940 class for the entire library. An instance of this class
56 | will be preinstantiated as Tlc. */
57 | class Tlc5940
58 | {
59 | public:
60 | void init(uint16_t initialValue = 0);
61 | void clear(void);
62 | uint8_t update(void);
63 | void set(TLC_CHANNEL_TYPE channel, uint16_t value);
64 | uint16_t get(TLC_CHANNEL_TYPE channel);
65 | void setAll(uint16_t value);
66 | #if VPRG_ENABLED
67 | void setAllDC(uint8_t value);
68 | #endif
69 | #if XERR_ENABLED
70 | uint8_t readXERR(void);
71 | #endif
72 |
73 | };
74 |
75 | void tlc_shift8_init(void);
76 | void tlc_shift8(uint8_t byte);
77 |
78 | #if VPRG_ENABLED
79 | void tlc_dcModeStart(void);
80 | void tlc_dcModeStop(void);
81 | #endif
82 |
83 | // for the preinstantiated Tlc variable.
84 | extern Tlc5940 Tlc;
85 |
86 | #endif
87 |
88 |
--------------------------------------------------------------------------------
/src/pinouts/ATmega_8.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_ATMEGA_8_H
20 | #define TLC_ATMEGA_8_H
21 |
22 | #if DATA_TRANSFER_MODE == TLC_SPI
23 | #warning SPI cannot be used on the ATmega8 because it interferes with timer2
24 | #warning setting DATA_TRANSFER_MODE to TLC_BITBANG
25 | #define DATA_TRANSFER_MODE TLC_BITBANG
26 | #endif
27 |
28 | /** \file
29 | SPI and timer pins for the ATmega8. Don't edit these. All
30 | changeable pins are defined in tlc_config.h */
31 |
32 | /** VPRG (Arduino digital pin 8) -> VPRG (TLC pin 27) */
33 | #define DEFAULT_VPRG_PIN PB0
34 | #define DEFAULT_VPRG_PORT PORTB
35 | #define DEFAULT_VPRG_DDR DDRB
36 |
37 | /** XERR (Arduino digital pin 12) -> XERR (TLC pin 16) */
38 | #define DEFAULT_XERR_PIN PB4
39 | #define DEFAULT_XERR_PORT PORTB
40 | #define DEFAULT_XERR_DDR DDRB
41 | #define DEFAULT_XERR_PINS PINB
42 |
43 | /** SIN (Arduino digital pin 7) -> SIN (TLC pin 26) */
44 | #define DEFAULT_BB_SIN_PIN PD7
45 | #define DEFAULT_BB_SIN_PORT PORTD
46 | #define DEFAULT_BB_SIN_DDR DDRD
47 | /** SCLK (Arduino digital pin 4) -> SCLK (TLC pin 25) */
48 | #define DEFAULT_BB_SCLK_PIN PD4
49 | #define DEFAULT_BB_SCLK_PORT PORTD
50 | #define DEFAULT_BB_SCLK_DDR DDRD
51 |
52 | /** MOSI (Arduino digital pin 11) -> SIN (TLC pin 26) */
53 | #define TLC_MOSI_PIN PB3
54 | #define TLC_MOSI_PORT PORTB
55 | #define TLC_MOSI_DDR DDRB
56 |
57 | /** SCK (Arduino digital pin 13) -> SCLK (TLC pin 25) */
58 | #define TLC_SCK_PIN PB5
59 | #define TLC_SCK_PORT PORTB
60 | #define TLC_SCK_DDR DDRB
61 |
62 | /** SS will be set to output as to not interfere with SPI master operation.
63 | If you have changed the pin-outs and the library doesn't seem to work
64 | or works intermittently, make sure this pin is set correctly. This pin
65 | will not be used by the library other than setting its direction to
66 | output. */
67 | #define TLC_SS_PIN PB2
68 | #define TLC_SS_DDR DDRB
69 |
70 | /** OC1A (Arduino digital pin 9) -> XLAT (TLC pin 24) */
71 | #define XLAT_PIN PB1
72 | #define XLAT_PORT PORTB
73 | #define XLAT_DDR DDRB
74 |
75 | /** OC1B (Arduino digital pin 10) -> BLANK (TLC pin 23) */
76 | #define BLANK_PIN PB2
77 | #define BLANK_PORT PORTB
78 | #define BLANK_DDR DDRB
79 |
80 | /** OC2B (Arduino digital pin 3) -> GSCLK (TLC pin 18) */
81 | #define GSCLK_PIN PD3
82 | #define GSCLK_PORT PORTD
83 | #define GSCLK_DDR DDRD
84 |
85 | #endif
86 |
87 |
--------------------------------------------------------------------------------
/src/pinouts/ATmega_xx4.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_ATMEGA_XX8_H
20 | #define TLC_ATMEGA_XX8_H
21 |
22 | /** \file
23 | SPI and timer pins for the ATmega164/324/644. Don't edit these. All
24 | changeable pins are defined in tlc_config.h */
25 |
26 | /** VPRG (Sanguino digital pin 15) -> VPRG (TLC pin 27) */
27 | #define DEFAULT_VPRG_PIN PD7
28 | #define DEFAULT_VPRG_PORT PORTD
29 | #define DEFAULT_VPRG_DDR DDRD
30 |
31 | /** XERR (Sanguino digital pin 6) -> XERR (TLC pin 16) */
32 | #define DEFAULT_XERR_PIN PB6
33 | #define DEFAULT_XERR_PORT PORTB
34 | #define DEFAULT_XERR_DDR DDRB
35 | #define DEFAULT_XERR_PINS PINB
36 |
37 | /** SIN (Sanguino digital pin 5) -> SIN (TLC pin 26) */
38 | #define DEFAULT_BB_SIN_PIN PB5
39 | #define DEFAULT_BB_SIN_PORT PORTB
40 | #define DEFAULT_BB_SIN_DDR DDRB
41 | /** SCLK (Sanguino digital pin 7) -> SCLK (TLC pin 25) */
42 | #define DEFAULT_BB_SCLK_PIN PB7
43 | #define DEFAULT_BB_SCLK_PORT PORTB
44 | #define DEFAULT_BB_SCLK_DDR DDRB
45 |
46 | /** MOSI (Sanguino digital pin 5) -> SIN (TLC pin 26) */
47 | #define TLC_MOSI_PIN PB5
48 | #define TLC_MOSI_PORT PORTB
49 | #define TLC_MOSI_DDR DDRB
50 |
51 | /** SCK (Sanguino digital pin 7) -> SCLK (TLC pin 25) */
52 | #define TLC_SCK_PIN PB7
53 | #define TLC_SCK_PORT PORTB
54 | #define TLC_SCK_DDR DDRB
55 |
56 | /** SS will be set to output as to not interfere with SPI master operation.
57 | If you have changed the pin-outs and the library doesn't seem to work
58 | or works intermittently, make sure this pin is set correctly. This pin
59 | will not be used by the library other than setting its direction to
60 | output. */
61 | #define TLC_SS_PIN PB4
62 | #define TLC_SS_DDR DDRB
63 |
64 | /** OC1A (Sanguino digital pin 13) -> XLAT (TLC pin 24) */
65 | #define XLAT_PIN PD5
66 | #define XLAT_PORT PORTD
67 | #define XLAT_DDR DDRD
68 |
69 | /** OC1B (Sanguino digital pin 12) -> BLANK (TLC pin 23) */
70 | #define BLANK_PIN PD4
71 | #define BLANK_PORT PORTD
72 | #define BLANK_DDR DDRD
73 |
74 | /** OC2B (Sanguino digital pin 14) -> GSCLK (TLC pin 18) */
75 | #define GSCLK_PIN PD6
76 | #define GSCLK_PORT PORTD
77 | #define GSCLK_DDR DDRD
78 |
79 | #endif
80 |
81 |
--------------------------------------------------------------------------------
/src/pinouts/ATmega_xx8.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_ATMEGA_XX8_H
20 | #define TLC_ATMEGA_XX8_H
21 |
22 | /** \file
23 | SPI and timer pins for the ATmega168/48/88. Don't edit these. All
24 | changeable pins are defined in tlc_config.h */
25 |
26 | /** VPRG (Arduino digital pin 8) -> VPRG (TLC pin 27) */
27 | #define DEFAULT_VPRG_PIN PB0
28 | #define DEFAULT_VPRG_PORT PORTB
29 | #define DEFAULT_VPRG_DDR DDRB
30 |
31 | /** XERR (Arduino digital pin 12) -> XERR (TLC pin 16) */
32 | #define DEFAULT_XERR_PIN PB4
33 | #define DEFAULT_XERR_PORT PORTB
34 | #define DEFAULT_XERR_DDR DDRB
35 | #define DEFAULT_XERR_PINS PINB
36 |
37 | /** SIN (Arduino digital pin 7) -> SIN (TLC pin 26) */
38 | #define DEFAULT_BB_SIN_PIN PD7
39 | #define DEFAULT_BB_SIN_PORT PORTD
40 | #define DEFAULT_BB_SIN_DDR DDRD
41 | /** SCLK (Arduino digital pin 4) -> SCLK (TLC pin 25) */
42 | #define DEFAULT_BB_SCLK_PIN PD4
43 | #define DEFAULT_BB_SCLK_PORT PORTD
44 | #define DEFAULT_BB_SCLK_DDR DDRD
45 |
46 | /** MOSI (Arduino digital pin 11) -> SIN (TLC pin 26) */
47 | #define TLC_MOSI_PIN PB3
48 | #define TLC_MOSI_PORT PORTB
49 | #define TLC_MOSI_DDR DDRB
50 |
51 | /** SCK (Arduino digital pin 13) -> SCLK (TLC pin 25) */
52 | #define TLC_SCK_PIN PB5
53 | #define TLC_SCK_PORT PORTB
54 | #define TLC_SCK_DDR DDRB
55 |
56 | /** SS will be set to output as to not interfere with SPI master operation.
57 | If you have changed the pin-outs and the library doesn't seem to work
58 | or works intermittently, make sure this pin is set correctly. This pin
59 | will not be used by the library other than setting its direction to
60 | output. */
61 | #define TLC_SS_PIN PB2
62 | #define TLC_SS_DDR DDRB
63 |
64 | /** OC1A (Arduino digital pin 9) -> XLAT (TLC pin 24) */
65 | #define XLAT_PIN PB1
66 | #define XLAT_PORT PORTB
67 | #define XLAT_DDR DDRB
68 |
69 | /** OC1B (Arduino digital pin 10) -> BLANK (TLC pin 23) */
70 | #define BLANK_PIN PB2
71 | #define BLANK_PORT PORTB
72 | #define BLANK_DDR DDRB
73 |
74 | /** OC2B (Arduino digital pin 3) -> GSCLK (TLC pin 18) */
75 | #define GSCLK_PIN PD3
76 | #define GSCLK_PORT PORTD
77 | #define GSCLK_DDR DDRD
78 |
79 | #endif
80 |
81 |
--------------------------------------------------------------------------------
/src/pinouts/Arduino_Mega.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef ARDUINO_MEGA_H
20 | #define ARDUINO_MEGA_H
21 |
22 | /** \file
23 | SPI and timer pins for the Arduino Mega. Don't edit these. All
24 | changeable pins are defined in tlc_config.h */
25 |
26 | /** VPRG (Mega pin 50) -> VPRG (TLC pin 27) */
27 | #define DEFAULT_VPRG_PIN PB3
28 | #define DEFAULT_VPRG_PORT PORTB
29 | #define DEFAULT_VPRG_DDR DDRB
30 |
31 | /** XERR (Mega pin 10) -> XERR (TLC pin 16) */
32 | #define DEFAULT_XERR_PIN PB4
33 | #define DEFAULT_XERR_PORT PORTB
34 | #define DEFAULT_XERR_DDR DDRB
35 | #define DEFAULT_XERR_PINS PINB
36 |
37 | /** SIN (Mega pin 51) -> SIN (TLC pin 26) */
38 | #define DEFAULT_BB_SIN_PIN PB2
39 | #define DEFAULT_BB_SIN_PORT PORTB
40 | #define DEFAULT_BB_SIN_DDR DDRB
41 | /** SCLK (Mega pin 52) -> SCLK (TLC pin 25) */
42 | #define DEFAULT_BB_SCLK_PIN PB1
43 | #define DEFAULT_BB_SCLK_PORT PORTB
44 | #define DEFAULT_BB_SCLK_DDR DDRB
45 |
46 | /** MOSI (Mega pin 51) -> SIN (TLC pin 26) */
47 | #define TLC_MOSI_PIN PB2
48 | #define TLC_MOSI_PORT PORTB
49 | #define TLC_MOSI_DDR DDRB
50 |
51 | /** SCK (Mega pin 52) -> SCLK (TLC pin 25) */
52 | #define TLC_SCK_PIN PB1
53 | #define TLC_SCK_PORT PORTB
54 | #define TLC_SCK_DDR DDRB
55 |
56 | // SS (Mega pin 53)
57 | /** SS will be set to output as to not interfere with SPI master operation.
58 | If you have changed the pin-outs and the library doesn't seem to work
59 | or works intermittently, make sure this pin is set correctly. This pin
60 | will not be used by the library other than setting its direction to
61 | output. */
62 | #define TLC_SS_PIN PB0
63 | #define TLC_SS_DDR DDRB
64 |
65 | /** OC1A (Mega pin 11) -> XLAT (TLC pin 24) */
66 | #define XLAT_PIN PB5
67 | #define XLAT_PORT PORTB
68 | #define XLAT_DDR DDRB
69 |
70 | /** OC1B (Mega pin 12) -> BLANK (TLC pin 23) */
71 | #define BLANK_PIN PB6
72 | #define BLANK_PORT PORTB
73 | #define BLANK_DDR DDRB
74 |
75 | /** OC2B (Mega pin 9) -> GSCLK (TLC pin 18) */
76 | #define GSCLK_PIN PH6
77 | #define GSCLK_PORT PORTH
78 | #define GSCLK_DDR DDRH
79 |
80 | #endif
81 |
82 |
--------------------------------------------------------------------------------
/src/pinouts/Teensy_xxU4.h:
--------------------------------------------------------------------------------
1 | #ifndef TLC_Teensy_xxU4_h
2 | #define TLC_Teensy_xxU4_h
3 |
4 | #if DATA_TRANSFER_MODE == TLC_BITBANG
5 | #error "If you want bitbang mode, insert pin defs here"
6 | #endif
7 |
8 | // MOSI (Teensy pin 2) -> SIN (TLC pin 26)
9 | #define TLC_MOSI_PIN 2
10 | #define TLC_MOSI_PORT PORTB
11 | #define TLC_MOSI_DDR DDRB
12 |
13 | // SCK (Teensy pin 1) -> SCLK (TLC pin 25)
14 | #define TLC_SCK_PIN 1
15 | #define TLC_SCK_PORT PORTB
16 | #define TLC_SCK_DDR DDRB
17 |
18 | // SS (Teensy pin 0)
19 | #define TLC_SS_PIN 0
20 | #define TLC_SS_DDR DDRB
21 |
22 | // OC1A (Teensy pin 14) -> XLAT (TLC pin 24)
23 | #define XLAT_PIN 5
24 | #define XLAT_PORT PORTB
25 | #define XLAT_DDR DDRB
26 |
27 | // OC1B (Teensy pin 15) -> BLANK (TLC pin 23)
28 | #define BLANK_PIN 6
29 | #define BLANK_PORT PORTB
30 | #define BLANK_DDR DDRB
31 |
32 | // OC3A (Teensy pin 9) -> GSCLK (TLC pin 18)
33 | #define GSCLK_PIN 6
34 | #define GSCLK_PORT PORTC
35 | #define GSCLK_DDR DDRC
36 | #define TLC_TIMER3_GSCLK 1
37 |
38 | #endif
39 |
40 |
--------------------------------------------------------------------------------
/src/pinouts/Teensypp_xxx6.h:
--------------------------------------------------------------------------------
1 | #ifndef TLC_Teensypp_xxx6_H
2 | #define TLC_Teensypp_xxx6_H
3 |
4 | #if DATA_TRANSFER_MODE == TLC_BITBANG
5 | #error "If you want bitbang mode, insert pin defs here"
6 | #endif
7 |
8 | // MOSI (Teensy++ pin 22) -> SIN (TLC pin 26)
9 | #define TLC_MOSI_PIN 2
10 | #define TLC_MOSI_PORT PORTB
11 | #define TLC_MOSI_DDR DDRB
12 |
13 | // SCK (Teensy++ pin 21) -> SCLK (TLC pin 25)
14 | #define TLC_SCK_PIN 1
15 | #define TLC_SCK_PORT PORTB
16 | #define TLC_SCK_DDR DDRB
17 |
18 | // SS (Teensy++ pin 20)
19 | #define TLC_SS_PIN 0
20 | #define TLC_SS_DDR DDRB
21 |
22 | // OC1A (Teensy++ pin 25) -> XLAT (TLC pin 24)
23 | #define XLAT_PIN 5
24 | #define XLAT_PORT PORTB
25 | #define XLAT_DDR DDRB
26 |
27 | // OC1B (Teensy++ pin 26) -> BLANK (TLC pin 23)
28 | #define BLANK_PIN 6
29 | #define BLANK_PORT PORTB
30 | #define BLANK_DDR DDRB
31 |
32 | // OC2B (Teensy++ pin 1) -> GSCLK (TLC pin 18)
33 | #define GSCLK_PIN 1
34 | #define GSCLK_PORT PORTD
35 | #define GSCLK_DDR DDRD
36 |
37 | #endif
38 |
39 |
--------------------------------------------------------------------------------
/src/pinouts/chip_includes.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_CHIP_INCLUDES_H
20 | #define TLC_CHIP_INCLUDES_H
21 |
22 | /** \file
23 | Includes the chip-specfic defaults and pin definitions. */
24 |
25 | #include
26 |
27 | #ifndef PB0
28 | #define PB0 PORTB0
29 | #define PB1 PORTB1
30 | #define PB2 PORTB2
31 | #define PB3 PORTB3
32 | #define PB4 PORTB4
33 | #define PB5 PORTB5
34 | #define PB6 PORTB6
35 | #define PB7 PORTB7
36 | #endif
37 | #ifndef PC0
38 | #define PC0 PORTC0
39 | #define PC1 PORTC1
40 | #define PC2 PORTC2
41 | #define PC3 PORTC3
42 | #define PC4 PORTC4
43 | #define PC5 PORTC5
44 | #define PC6 PORTC6
45 | #define PC7 PORTC7
46 | #endif
47 | #ifndef PD0
48 | #define PD0 PORTD0
49 | #define PD1 PORTD1
50 | #define PD2 PORTD2
51 | #define PD3 PORTD3
52 | #define PD4 PORTD4
53 | #define PD5 PORTD5
54 | #define PD6 PORTD6
55 | #define PD7 PORTD7
56 | #endif
57 | #ifndef PH0
58 | #define PH0 PORTH0
59 | #define PH1 PORTH1
60 | #define PH2 PORTH2
61 | #define PH3 PORTH3
62 | #define PH4 PORTH4
63 | #define PH5 PORTH5
64 | #define PH6 PORTH6
65 | #define PH7 PORTH7
66 | #endif
67 |
68 | /* Chip Specific Pinouts */
69 | #if defined (__AVR_ATmega168__) \
70 | || defined (__AVR_ATmega168P__) \
71 | || defined (__AVR_ATmega88P__) \
72 | || defined (__AVR_ATmega88__) \
73 | || defined (__AVR_ATmega48P__) \
74 | || defined (__AVR_ATmega48__) \
75 | || defined (__AVR_ATmega328P__)
76 |
77 | /* Diecimila / Duemilanove / almost everything */
78 | #include "ATmega_xx8.h"
79 |
80 | #elif defined (__AVR_ATmega8__)
81 |
82 | /* ATmega8 */
83 | #include "ATmega_8.h"
84 |
85 | #elif defined (__AVR_ATmega164P__) \
86 | || defined (__AVR_ATmega324P__) \
87 | || defined (__AVR_ATmega644__) \
88 | || defined (__AVR_ATmega644P__)
89 |
90 | /* Sanguino */
91 | #include "ATmega_xx4.h"
92 |
93 | #elif defined (__AVR_ATmega640__) \
94 | || defined (__AVR_ATmega1280__) \
95 | || defined (__AVR_ATmega1281__) \
96 | || defined (__AVR_ATmega2560__) \
97 | || defined (__AVR_ATmega2561__)
98 |
99 | /* Arduino Mega */
100 | #include "Arduino_Mega.h"
101 |
102 | #elif defined (__AVR_ATmega32U4__)
103 |
104 | /* Teensy 2.0 */
105 | #include "Teensy_xxU4.h"
106 |
107 | #elif defined (__AVR_AT90USB646__) \
108 | || defined (__AVR_AT90USB1286__)
109 |
110 | /* Teensy++ 2.0 */
111 | #include "Teensypp_xxx6.h"
112 |
113 | #else
114 | #error "Unknown Chip!"
115 | #endif
116 |
117 | #endif
118 |
119 |
--------------------------------------------------------------------------------
/src/tlc_animations.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_ANIMATIONS_H
20 | #define TLC_ANIMATIONS_H
21 |
22 | /** \file
23 | TLC Animation functions. These play animations from PROGMEM. */
24 |
25 | #include
26 | #include
27 |
28 | #include "tlc_config.h"
29 | #include "SparkFun_Tlc5940.h"
30 | #include "tlc_progmem_utils.h"
31 |
32 | /** The currently playing animation */
33 | prog_uint8_t *tlc_currentAnimation;
34 | /** The number of frames in the current animation */
35 | volatile uint16_t tlc_animationFrames;
36 | /** The number of PWM periods to display each frame - 1 */
37 | volatile uint16_t tlc_animationPeriodsPerFrame;
38 | /** The current number of periods we've displayed this frame for */
39 | volatile uint16_t tlc_animationPeriodsWait;
40 |
41 | volatile void tlc_animationXLATCallback(void);
42 | void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames, uint16_t periodsPerFrame);
43 |
44 | /** \addtogroup ExtendedFunctions
45 | \code #include "tlc_animations.h" \endcode
46 | - void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames,
47 | uint16_t periodsPerFrame) - plays an animation from progmem. */
48 | /* @{ */
49 |
50 | /** Plays an animation from progmem in the "background" (with interrupts).
51 | \param animation A progmem array of grayscale data, length NUM_TLCS *
52 | 24 * frames, in reverse order. Ensure that there is not an update
53 | waiting to happen before calling this.
54 | \param frames the number of frames in animation
55 | \param periodsPerFrame number of PWM periods to wait between each frame
56 | (0 means play the animation as fast as possible).
57 | The default PWM period for a 16MHz clock is 1.024ms. */
58 | void tlc_playAnimation(prog_uint8_t *animation, uint16_t frames, uint16_t periodsPerFrame)
59 | {
60 | tlc_currentAnimation = animation;
61 | tlc_animationFrames = frames;
62 | tlc_animationPeriodsPerFrame = periodsPerFrame;
63 | tlc_animationPeriodsWait = 0;
64 | tlc_onUpdateFinished = tlc_animationXLATCallback;
65 | tlc_animationXLATCallback();
66 | }
67 |
68 | /** This is called by the XLAT interrupt every PWM period to do stuff. */
69 | volatile void tlc_animationXLATCallback(void)
70 | {
71 | if (tlc_animationPeriodsWait) {
72 | tlc_animationPeriodsWait--;
73 | set_XLAT_interrupt();
74 | } else {
75 | if (tlc_animationFrames) {
76 | tlc_setGSfromProgmem(tlc_currentAnimation +
77 | (--tlc_animationFrames * NUM_TLCS * 24));
78 | tlc_animationPeriodsWait = tlc_animationPeriodsPerFrame;
79 | Tlc.update();
80 | } else { // animation is done
81 | tlc_onUpdateFinished = 0;
82 | }
83 | }
84 | }
85 |
86 | /* @} */
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/src/tlc_config.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_CONFIG_H
20 | #define TLC_CONFIG_H
21 |
22 | #include
23 |
24 | /** \file
25 | Configuration for the Arduino Tlc5940 library. After making changes to
26 | this file, delete Tlc5940.o in this folder so the changes are applied.
27 |
28 | A summary of all the options:
29 | - Number of TLCs daisy-chained: NUM_TLCS (default 1)
30 | - Enable/Disable VPRG functionality: VPRG_ENABLED (default 0)
31 | - Enable/Disable XERR functionality: XERR_ENABLED (default 0)
32 | - Should the library use bit-banging (any pins) or hardware SPI (faster):
33 | DATA_TRANSFER_MODE (default TLC_SPI)
34 | - Which pins to use for bit-banging: SIN_PIN, SIN_PORT, SIN_DDR and
35 | SCLK_PIN, SCLK_PORT, SCLK_DDR
36 | - The PWM period: TLC_PWM_PERIOD (be sure to change TLC_GSCLK_PERIOD
37 | accordingly!)
38 |
39 | How to change the pin mapping:
40 | - Arduino digital pin 0-7 = PORTD, PD0-7
41 | - Arduino digital pin 8-13 = PORTB, PB0-5
42 | - Arduino analog pin 0-5 = PORTC, PC0-5 */
43 |
44 | /** Bit-bang using any two i/o pins */
45 | #define TLC_BITBANG 1
46 | /** Use the much faster hardware SPI module */
47 | #define TLC_SPI 2
48 |
49 | /* ------------------------ START EDITING HERE ----------------------------- */
50 |
51 | /** Number of TLCs daisy-chained. To daisy-chain, attach the SOUT (TLC pin 17)
52 | of the first TLC to the SIN (TLC pin 26) of the next. The rest of the pins
53 | are attached normally.
54 | \note Each TLC needs it's own IREF resistor */
55 | #define NUM_TLCS 1
56 |
57 | /** Determines how data should be transfered to the TLCs. Bit-banging can use
58 | any two i/o pins, but the hardware SPI is faster.
59 | - Bit-Bang = TLC_BITBANG
60 | - Hardware SPI = TLC_SPI (default) */
61 | #define DATA_TRANSFER_MODE TLC_SPI
62 |
63 | /* This include is down here because the files it includes needs the data
64 | transfer mode */
65 | #include "pinouts/chip_includes.h"
66 |
67 | /* Set DATA_TRANSFER_MODE to TLC_BITBANG and change the pins below if you need
68 | to use different pins for sin and sclk. The defaults are defined in
69 | pinouts/ATmega_xx8.h for most Arduino's. */
70 |
71 | #if DATA_TRANSFER_MODE == TLC_BITBANG
72 | /** SIN (TLC pin 26) */
73 | #define SIN_PIN DEFAULT_BB_SIN_PIN
74 | #define SIN_PORT DEFAULT_BB_SIN_PORT
75 | #define SIN_DDR DEFAULT_BB_SIN_DDR
76 | /** SCLK (TLC pin 25) */
77 | #define SCLK_PIN DEFAULT_BB_SCLK_PIN
78 | #define SCLK_PORT DEFAULT_BB_SCLK_PORT
79 | #define SCLK_DDR DEFAULT_BB_SCLK_DDR
80 | #endif
81 |
82 |
83 | /** If more than 16 TLCs are daisy-chained, the channel type has to be uint16_t.
84 | Default is uint8_t, which supports up to 16 TLCs. */
85 | #define TLC_CHANNEL_TYPE uint8_t
86 |
87 | /** Determines how long each PWM period should be, in clocks.
88 | \f$\displaystyle f_{PWM} = \frac{f_{osc}}{2 * TLC\_PWM\_PERIOD} Hz \f$
89 | \f$\displaystyle TLC\_PWM\_PERIOD = \frac{f_{osc}}{2 * f_{PWM}} \f$
90 | This is related to TLC_GSCLK_PERIOD:
91 | \f$\displaystyle TLC\_PWM\_PERIOD =
92 | \frac{(TLC\_GSCLK\_PERIOD + 1) * 4096}{2} \f$
93 | \note The default of 8192 means the PWM frequency is 976.5625Hz */
94 | #define TLC_PWM_PERIOD 8192
95 |
96 | /** Determines how long each period GSCLK is.
97 | This is related to TLC_PWM_PERIOD:
98 | \f$\displaystyle TLC\_GSCLK\_PERIOD =
99 | \frac{2 * TLC\_PWM\_PERIOD}{4096} - 1 \f$
100 | \note Default is 3 */
101 | #define TLC_GSCLK_PERIOD 3
102 |
103 | /** Enables/disables VPRG (TLC pin 27) functionality. If you need to set dot
104 | correction data, this needs to be enabled.
105 | - 0 VPRG is not connected. TLC pin 27 must be grounded! (default)
106 | - 1 VPRG is connected
107 | \note VPRG to GND inputs grayscale data, VPRG to Vcc inputs dot-correction
108 | data */
109 | #define VPRG_ENABLED 0
110 |
111 | /** Enables/disables XERR (TLC pin 16) functionality to check for shorted/broken
112 | LEDs
113 | - 0 XERR is not connected (default)
114 | - 1 XERR is connected
115 | \note XERR is active low */
116 | #define XERR_ENABLED 0
117 |
118 | /* You can change the VPRG and XERR pins freely. The defaults are defined in
119 | the chip-specific pinouts: see pinouts/ATmega_xx8.h for most Arduino's. */
120 |
121 | #if VPRG_ENABLED
122 | /** VPRG (TLC pin 27) */
123 | #define VPRG_PIN DEFAULT_VPRG_PIN
124 | #define VPRG_PORT DEFAULT_VPRG_PORT
125 | #define VPRG_DDR DEFAULT_VPRG_DDR
126 | #endif
127 |
128 | #if XERR_ENABLED
129 | /** XERR (TLC pin 16) */
130 | #define XERR_PIN DEFAULT_XERR_PIN
131 | #define XERR_PORT DEFAULT_XERR_PORT
132 | #define XERR_DDR DEFAULT_XERR_DDR
133 | #define XERR_PINS DEFAULT_XERR_PINS
134 | #endif
135 |
136 | /* ------------------------- STOP EDITING HERE ----------------------------- */
137 |
138 | #if DATA_TRANSFER_MODE == TLC_SPI
139 | /** SIN (TLC pin 26) */
140 | #define SIN_PIN TLC_MOSI_PIN
141 | #define SIN_PORT TLC_MOSI_PORT
142 | #define SIN_DDR TLC_MOSI_DDR
143 | /** SCLK (TLC pin 25) */
144 | #define SCLK_PIN TLC_SCK_PIN
145 | #define SCLK_PORT TLC_SCK_PORT
146 | #define SCLK_DDR TLC_SCK_DDR
147 | #endif
148 |
149 |
150 |
151 | #if !(DATA_TRANSFER_MODE == TLC_BITBANG \
152 | || DATA_TRANSFER_MODE == TLC_SPI)
153 | #error "Invalid DATA_TRANSFER_MODE specified, see DATA_TRANSFER_MODE"
154 | #endif
155 |
156 | /* Various Macros */
157 |
158 | /** Arranges 2 grayscale values (0 - 4095) in the packed array format (3 bytes).
159 | This is for array initializers only: the output is three comma seperated
160 | 8-bit values. */
161 | #define GS_DUO(a, b) ((a) >> 4), ((a) << 4) | ((b) >> 8), (b)
162 |
163 |
164 | #if VPRG_ENABLED
165 | /** Arranges 4 dot correction values (0 - 63) in the packed array format.
166 | \see setDCtoProgmemArray */
167 | #define DC_QUARTET(a, b, c, d) ((a) << 2) | ((b) >> 4), \
168 | ((b) << 4) | ((c) >> 2), \
169 | ((c) << 6) | (d)
170 | #endif
171 |
172 | #endif
173 |
174 |
--------------------------------------------------------------------------------
/src/tlc_fades.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_FADES_H
20 | #define TLC_FADES_H
21 |
22 | /** \file
23 | TLC fading functions. */
24 |
25 | #include
26 |
27 | #include "SparkFun_Tlc5940.h"
28 |
29 | #if defined(ARDUINO) && ARDUINO >= 100
30 | #include "Arduino.h"
31 | #else
32 | #include "WProgram.h"
33 | #endif
34 |
35 | #ifndef TLC_FADE_BUFFER_LENGTH
36 | /** The default fade buffer length (24). Uses 24*13 = 312 bytes of ram. */
37 | #define TLC_FADE_BUFFER_LENGTH 24
38 | #endif
39 |
40 | /** Data for a single fade */
41 | struct Tlc_Fade {
42 | TLC_CHANNEL_TYPE channel; /**< channel this fade is on */
43 | int16_t startValue; /**< value when the fade starts (0 - 4095) */
44 | int16_t changeValue; /**< start + changeValue = endValue (0 - 4095) */
45 | uint32_t startMillis; /**< millis() when to start */
46 | uint32_t endMillis; /**< millis() when to end */
47 | } tlc_fadeBuffer[TLC_FADE_BUFFER_LENGTH];
48 |
49 | /** The current fade buffer size */
50 | uint8_t tlc_fadeBufferSize;
51 |
52 | uint8_t tlc_updateFades();
53 | uint8_t tlc_updateFades(uint32_t currentMillis);
54 | uint8_t tlc_addFade(struct Tlc_Fade *fade);
55 | uint8_t tlc_addFade(TLC_CHANNEL_TYPE channel, int16_t startValue,
56 | int16_t endValue, uint32_t startMillis, uint32_t endMillis);
57 | uint8_t tlc_isFading(TLC_CHANNEL_TYPE channel);
58 | uint8_t tlc_removeFades(TLC_CHANNEL_TYPE channel);
59 | static void tlc_removeFadeFromBuffer(struct Tlc_Fade *current,
60 | struct Tlc_Fade *end);
61 |
62 | /** \addtogroup ExtendedFunctions
63 | \code #include "tlc_fades.h" \endcode
64 | - uint8_t tlc_updateFades() - updates all fades
65 | - uint8_t tlc_updateFades(uint32_t currentMillis) - updates fades using
66 | currentMillis as the current time
67 | - uint8_t tlc_addFade(struct Tlc_Fade *fade) - copies fade into the
68 | fade buffer
69 | - uint8_t tlc_addFade(TLC_CHANNEL_TYPE channel, int16_t startValue,
70 | int16_t endValue, uint32_t startMillis, uint32_t endMillis) - adds
71 | a fade to the fade buffer
72 | - uint8_t tlc_isFading(TLC_CHANNEL_TYPE channel) - returns 1 if there's
73 | a fade on this channel in the buffer
74 | - uint8_t tlc_removeFades(TLC_CHANNEL_TYPE channel) - removes all fades
75 | on channel */
76 | /* @{ */
77 |
78 | /** Adds a fade to the buffer.
79 | \param fade the fade to be copied into the buffer
80 | \returns 0 if the fade buffer is full, fadeBufferSize if added successfully
81 | */
82 | uint8_t tlc_addFade(struct Tlc_Fade *fade)
83 | {
84 | if (tlc_fadeBufferSize == TLC_FADE_BUFFER_LENGTH) {
85 | return 0; // fade buffer full
86 | }
87 | struct Tlc_Fade *p = tlc_fadeBuffer + tlc_fadeBufferSize++;
88 | p->channel = fade->channel;
89 | p->startValue = fade->startValue;
90 | p->changeValue = fade->changeValue;
91 | p->startMillis = fade->startMillis;
92 | p->endMillis = fade->endMillis;
93 | return tlc_fadeBufferSize;
94 | }
95 |
96 | /** Adds a fade to the fade buffer.
97 | \param channel the ouput channel this fade is on
98 | \param startValue the value at the start of the fade
99 | \param endValue the value at the end of the fade
100 | \param startMillis the millis() when to start the fade
101 | \param endMillis the millis() when to end the fade
102 | \returns 0 if the fade buffer is full, fadeBufferSize if added successfully
103 | */
104 | uint8_t tlc_addFade(TLC_CHANNEL_TYPE channel, int16_t startValue,
105 | int16_t endValue, uint32_t startMillis, uint32_t endMillis)
106 | {
107 | if (tlc_fadeBufferSize == TLC_FADE_BUFFER_LENGTH) {
108 | return 0; // fade buffer full
109 | }
110 | struct Tlc_Fade *p = tlc_fadeBuffer + tlc_fadeBufferSize++;
111 | p->channel = channel;
112 | p->startValue = startValue;
113 | p->changeValue = endValue - startValue;
114 | p->startMillis = startMillis;
115 | p->endMillis = endMillis;
116 | return tlc_fadeBufferSize;
117 | }
118 |
119 | /** Checks to see if any fades are happening on channel
120 | \param channel the channel to check
121 | \returns 1 if there is a fade in the buffer on this channel, 0 otherwise */
122 | uint8_t tlc_isFading(TLC_CHANNEL_TYPE channel)
123 | {
124 | struct Tlc_Fade *end = tlc_fadeBuffer + tlc_fadeBufferSize;
125 | for (struct Tlc_Fade *p = tlc_fadeBuffer; p < end; p++) {
126 | if (p->channel == channel) {
127 | return 1;
128 | }
129 | }
130 | return 0;
131 | }
132 |
133 | /** Removes any fades from the fade buffer on this channel.
134 | \param channel which channel the fades are on
135 | \returns how many fades were removed */
136 | uint8_t tlc_removeFades(TLC_CHANNEL_TYPE channel)
137 | {
138 | uint8_t removed = 0;
139 | struct Tlc_Fade *end = tlc_fadeBuffer + tlc_fadeBufferSize;
140 | for (struct Tlc_Fade *p = tlc_fadeBuffer; p < end; p++) {
141 | if (p->channel == channel) {
142 | removed++;
143 | tlc_removeFadeFromBuffer(p, --end);
144 | }
145 | }
146 | return removed;
147 | }
148 |
149 | /** Copies the end of the buffer to the current and decrements
150 | tlc_fadeBufferSize. This will change the end of the buffer (pass by
151 | reference)
152 | \param current the fade to be removed
153 | \param endp the end of the fade buffer (pointer to pointer) */
154 | static void tlc_removeFadeFromBuffer(struct Tlc_Fade *current,
155 | struct Tlc_Fade *endp)
156 | {
157 | if (endp != current) { // if this is not the last fade
158 | current->channel = endp->channel;
159 | current->startValue = endp->startValue;
160 | current->changeValue = endp->changeValue;
161 | current->startMillis = endp->startMillis;
162 | current->endMillis = endp->endMillis;
163 | }
164 | tlc_fadeBufferSize--;
165 | }
166 |
167 | /** Updates fades using millis()
168 | \returns 0 if there are no fades left in the buffer. */
169 | uint8_t tlc_updateFades()
170 | {
171 | return tlc_updateFades(millis());
172 | }
173 |
174 | /** Updates any running fades.
175 | \param currentMillis the current millis() time.
176 | \returns 0 if there are no fades left in the buffer. */
177 | uint8_t tlc_updateFades(uint32_t currentMillis)
178 | {
179 | struct Tlc_Fade *end = tlc_fadeBuffer + tlc_fadeBufferSize;
180 | uint8_t needsUpdate = 0;
181 | for (struct Tlc_Fade *p = tlc_fadeBuffer; p < end;){
182 | if (currentMillis >= p->endMillis) { // fade done
183 | Tlc.set(p->channel, p->startValue + p->changeValue);
184 | needsUpdate = 1;
185 | tlc_removeFadeFromBuffer(p, --end);
186 | continue;
187 | } else {
188 | uint32_t startMillis = p->startMillis;
189 | if (currentMillis >= startMillis) {
190 | Tlc.set(p->channel, p->startValue + p->changeValue
191 | * (int32_t)(currentMillis - startMillis)
192 | / (int32_t)(p->endMillis - startMillis));
193 | needsUpdate = 1;
194 | }
195 | }
196 | p++;
197 | }
198 | if (needsUpdate) {
199 | Tlc.update();
200 | if (tlc_fadeBufferSize == 0) {
201 | while (tlc_needXLAT)
202 | ;
203 | }
204 | }
205 | return tlc_fadeBufferSize;
206 | }
207 |
208 | /* @} */
209 |
210 | #endif
211 |
212 |
--------------------------------------------------------------------------------
/src/tlc_progmem_utils.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_PROGMEM_UTILS_H
20 | #define TLC_PROGMEM_UTILS_H
21 |
22 | /** \file
23 | PROGMEM utility functions for setting grayscale or dot correction data
24 | from PROGMEM. See the UsingProgmem Example for an example. */
25 |
26 | #include
27 | #include
28 |
29 | #include "tlc_config.h"
30 | #include "SparkFun_Tlc5940.h"
31 |
32 | void tlc_setGSfromProgmem(prog_uint8_t *gsArray);
33 | #if VPRG_ENABLED
34 | void tlc_setDCfromProgmem(prog_uint8_t *dcArray);
35 | #endif
36 |
37 | /** \addtogroup ExtendedFunctions
38 | \code #include "tlc_progmem_utils.h" \endcode
39 | - void tlc_setGSfromProgmem(prog_uint8_t *gsArray) - copies the progmem
40 | grayscale to current grayscale array. Requires a
41 | \link Tlc5940::update Tlc.update() \endlink.
42 | - void tlc_setDCfromProgmem(prog_uint8_t *dcArray) - shifts the data from a
43 | progmem dot correction array (doesn't need an update). */
44 | /* @{ */
45 |
46 | /** Sets the grayscale data from an array in progmem. This doesn't shift out
47 | any data: call Tlc.update(). An example:
48 | \code
49 | #include "tlc_progmem_utils.h"
50 | prog_uint8_t gsArray1[NUM_TLCS * 24] = {
51 | GS_DUO((4095 * 16)/16, (4095 * 15)/16), GS_DUO((4095 * 14)/16, (4095 * 13)/16),
52 | GS_DUO((4095 * 12)/16, (4095 * 11)/16), GS_DUO((4095 * 10)/16, (4095 * 9)/16),
53 | GS_DUO((4095 * 8)/16, (4095 * 7)/16), GS_DUO((4095 * 6)/16, (4095 * 5)/16),
54 | GS_DUO((4095 * 4)/16, (4095 * 3)/16), GS_DUO((4095 * 2)/16, (4095 * 1)/16),
55 | };
56 |
57 | // sometime after Tlc.init()
58 | tlc_setGSfromProgmem(gsArray1);
59 | Tlc.update();
60 | \endcode
61 | This would set a ramp of values from OUT0 to OUT15. (Although the
62 | NUM_TLCS * 24 looks like an error, each #GS_DUO is 3 bytes). The array
63 | would have to be expanded if #NUM_TLCS != 1.
64 |
65 | The format of the grayscale array is explained in #tlc_GSData.
66 |
67 | \param gsArray A progmem array of grayscale data. */
68 | void tlc_setGSfromProgmem(prog_uint8_t *gsArray)
69 | {
70 | prog_uint8_t *gsArrayp = gsArray;
71 | uint8_t *gsDatap = tlc_GSData;
72 | while (gsDatap < tlc_GSData + NUM_TLCS * 24) {
73 | *gsDatap++ = pgm_read_byte(gsArrayp++);
74 | *gsDatap++ = pgm_read_byte(gsArrayp++);
75 | *gsDatap++ = pgm_read_byte(gsArrayp++);
76 | }
77 | }
78 |
79 |
80 | #if VPRG_ENABLED
81 |
82 | /** \addtogroup ReqVPRG_ENABLED
83 | From tlc_progmem_utils.h:
84 | - tlc_setDCfromProgmem(prog_uint8_t *dcArray) - shifts the data from a
85 | progmem dot correction array (doesn't need an update). */
86 | /* @{ */
87 |
88 | /** Sets the dot correction data from an array in progmem. An example:
89 | \code
90 | #include "tlc_progmem_utils.h"
91 | prog_uint8_t dcArray1[NUM_TLCS * 12] = {
92 | DC_QUARTET(32, 63, 32, 63), DC_QUARTET(32, 63, 32, 63),
93 | DC_QUARTET(32, 63, 32, 63), DC_QUARTET(32, 63, 32, 63),
94 | };
95 |
96 | // sometime after Tlc.init()
97 | tlc_setDCfromProgmem(dcArray1);
98 | \endcode
99 | This would set every other channel to have a dot correction value of 32.
100 | (Although the NUM_TLCS * 12 looks like an error, each #DC_QUARTET is 3
101 | bytes). The array would have to be expanded if #NUM_TLCS != 1.
102 |
103 | The Format of the array is similar to #tlc_GSData, the last channel of
104 | the last TLC is the first value in the array. In the example above,
105 | the first 32 is setting OUT15, and the last 63 is setting OUT0.
106 |
107 | \param dcArray A progmem array of dot correction data to be shifted out.
108 | \see \link Tlc5940::setAllDC Tlc.setAllDC \endlink */
109 | void tlc_setDCfromProgmem(prog_uint8_t *dcArray)
110 | {
111 | tlc_dcModeStart();
112 |
113 | prog_uint8_t *p = dcArray;
114 | prog_uint8_t *dcArrayEnd = dcArray + NUM_TLCS * 12;
115 | while (p < dcArrayEnd) {
116 | tlc_shift8(pgm_read_byte(p++));
117 | }
118 | XLAT_PORT |= _BV(XLAT_PIN);
119 | XLAT_PORT &= ~_BV(XLAT_PIN);
120 |
121 | tlc_dcModeStop();
122 | }
123 |
124 | /* @} */
125 |
126 | #endif
127 |
128 | /* @} */
129 |
130 | #endif
131 |
132 |
--------------------------------------------------------------------------------
/src/tlc_servos.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_SERVOS_H
20 | #define TLC_SERVOS_H
21 |
22 | /** \file
23 | TLC servo functions. */
24 |
25 | #include
26 | #include "SparkFun_Tlc5940.h"
27 |
28 | #ifndef SERVO_MAX_ANGLE
29 | /** The maximum angle of the servo. */
30 | #define SERVO_MAX_ANGLE 180
31 | #endif
32 | #ifndef SERVO_MIN_WIDTH
33 | /** The 1ms pulse width for zero degrees (0 - 4095). */
34 | #define SERVO_MIN_WIDTH 204
35 | #endif
36 | #ifndef SERVO_MAX_WIDTH
37 | /** The 2ms pulse width for 180 degrees (0 - 4095). */
38 | #define SERVO_MAX_WIDTH 410
39 | #endif
40 | #ifndef SERVO_TIMER1_TOP
41 | /** The top value for XLAT and BLANK pulses. This is with the div8 prescale,
42 | so
43 | \f$\displaystyle f_{PWM} = \frac{f_{osc}}{2 * 8 * SERVO\_TIMER1\_TOP} \f$
44 | The default is 20000, which corresponds to 50Hz. */
45 | #define SERVO_TIMER1_TOP 20000
46 | #endif
47 | #ifndef SERVO_TIMER2_TOP
48 | /** The top value for GSCLK pulses. Related to SERVO_TIMER1_TOP by
49 | \f$\displaystyle SERVO\_TIMER2\_TOP =
50 | \frac{2 * 8 * SERVO\_TIMER1\_TOP}{4096} - 1 \f$
51 | The default is 77. */
52 | #define SERVO_TIMER2_TOP 77
53 | #endif
54 |
55 | void tlc_initServos(uint8_t initAngle = 0);
56 | void tlc_setServo(TLC_CHANNEL_TYPE channel, uint8_t angle);
57 | uint8_t tlc_getServo(TLC_CHANNEL_TYPE channel);
58 | uint16_t tlc_angleToVal(uint8_t angle);
59 | uint8_t tlc_valToAngle(uint16_t value);
60 |
61 | /** \addtogroup ExtendedFunctions
62 | \code #include "tlc_servos.h" \endcode
63 | - void tlc_initServos(uint8_t initAngle = 0) - initializes the tlc for
64 | servos.
65 | - void tlc_setServo(TLC_CHANNEL_TYPE channel, uint8_t angle) - sets a
66 | servo to an angle
67 | - uint8_t tlc_getServo(TLC_CHANNEL_TYPE channel) - gets the currently set
68 | servo angle */
69 | /* @{ */
70 |
71 | /** Initializes the tlc.
72 | \param initAngle the initial angle to set all servos to
73 | (0 - SERVO_MAX_ANGLE). */
74 | void tlc_initServos(uint8_t initAngle)
75 | {
76 | Tlc.init(tlc_angleToVal(initAngle));
77 | TCCR1B &= ~(_BV(CS12) | _BV(CS11) | _BV(CS10)); // stop timer1
78 | ICR1 = SERVO_TIMER1_TOP;
79 | TCNT1 = 0;
80 | #ifdef TLC_ATMEGA_8_H
81 | uint8_t oldTCCR2 = TCCR2;
82 | TCCR2 = 0;
83 | TCNT2 = 0;
84 | OCR2 = SERVO_TIMER2_TOP / 2;
85 | TCCR2 = oldTCCR2;
86 | #else
87 | uint8_t oldTCCR2B = TCCR2B;
88 | TCCR2B = 0;
89 | TCNT2 = 0;
90 | OCR2A = SERVO_TIMER2_TOP;
91 | TCCR2B = oldTCCR2B;
92 | #endif
93 | TCCR1B |= _BV(CS11); // start timer1 with div 8 prescale
94 | }
95 |
96 | /** Sets a servo on channel to angle.
97 | \param channel which channel to set
98 | \param angle (0 - SERVO_MAX_ANGLE) */
99 | void tlc_setServo(TLC_CHANNEL_TYPE channel, uint8_t angle)
100 | {
101 | Tlc.set(channel, tlc_angleToVal(angle));
102 | }
103 |
104 | /** Gets the current angle that channel is set to.
105 | \param channel which channel to get */
106 | uint8_t tlc_getServo(TLC_CHANNEL_TYPE channel)
107 | {
108 | return tlc_valToAngle(Tlc.get(channel));
109 | }
110 |
111 | /** Converts and angle (0 - SERVO_MAX_ANGLE) to the inverted tlc channel value
112 | (4095 - 0). */
113 | uint16_t tlc_angleToVal(uint8_t angle)
114 | {
115 | return 4095 - SERVO_MIN_WIDTH - (
116 | ((uint16_t)(angle) * (uint16_t)(SERVO_MAX_WIDTH - SERVO_MIN_WIDTH))
117 | / SERVO_MAX_ANGLE);
118 | }
119 |
120 | /** Converts an inverted tlc channel value (4095 - 0) into an angle (0 -
121 | SERVO_MAX_ANGLE). */
122 | uint8_t tlc_valToAngle(uint16_t value)
123 | {
124 | return SERVO_MAX_ANGLE * (4095 - SERVO_MIN_WIDTH - value)
125 | / (SERVO_MAX_WIDTH - SERVO_MIN_WIDTH);
126 | }
127 |
128 | /* @} */
129 |
130 | #endif
131 |
132 |
--------------------------------------------------------------------------------
/src/tlc_shifts.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2009 by Alex Leone
2 |
3 | This file is part of the Arduino TLC5940 Library.
4 |
5 | The Arduino TLC5940 Library is free software: you can redistribute it
6 | and/or modify it under the terms of the GNU General Public License as
7 | published by the Free Software Foundation, either version 3 of the
8 | License, or (at your option) any later version.
9 |
10 | The Arduino TLC5940 Library is distributed in the hope that it will be
11 | useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with The Arduino TLC5940 Library. If not, see
17 | . */
18 |
19 | #ifndef TLC_SHIFTS_H
20 | #define TLC_SHIFTS_H
21 |
22 | /** \file
23 | TLC channel shifting functions. */
24 |
25 | #include "SparkFun_Tlc5940.h"
26 |
27 | uint16_t tlc_shiftUp(uint16_t zeroValue = 0);
28 | uint16_t tlc_shiftDown(uint16_t topValue = 0);
29 |
30 | /** \addtogroup ExtendedFunctions
31 | \code #include "tlc_shifts.h" \endcode
32 | - uint16_t tlc_shiftUp(uint16_t zeroValue = 0) - shifts all channel data
33 | up (OUT0 becomes OUT1 ...) and returns OUT15
34 | - uint16_t tlc_shiftDown(uint16_t topValue = 0) - shifts all channel data
35 | down (OUT15 becomes OUT14 ...) and returns OUT0 */
36 | /* @{ */
37 |
38 | /** Shifts all the channel data up (OUT0 becomes OUT1 ...). Needs a
39 | Tlc.update() after.
40 | \param zeroValue the value of channel 0.
41 | \returns the value that was shifted off the end (OUT15) */
42 | uint16_t tlc_shiftUp(uint16_t zeroValue)
43 | {
44 | uint16_t topValue = ((uint16_t)(*tlc_GSData) << 4)
45 | | (*(tlc_GSData + 1) >> 4);
46 | uint8_t *p = tlc_GSData + 1;
47 | while (p < tlc_GSData + NUM_TLCS * 24 - 1) {
48 | *(p - 1) = (*p << 4) | (*(p + 1) >> 4);
49 | *p = (*(p + 1) << 4) | (*(p + 2) >> 4);
50 | p += 2;
51 | }
52 | *(tlc_GSData + NUM_TLCS * 24 - 2) = (*(tlc_GSData + NUM_TLCS * 24 - 1) << 4)
53 | | ((zeroValue & 0x0F00) >> 8);
54 | *(tlc_GSData + NUM_TLCS * 24 - 1) = (uint8_t)zeroValue;
55 | return topValue;
56 | }
57 |
58 | /** Shifts all the channel data down (OUT 15 -> OUT 14 ...). Needs a
59 | Tlc.update() after.
60 | \param topValue the value of Tlc (n) channel 15.
61 | \returns the value that was shifted off the bottom (OUT0) */
62 | uint16_t tlc_shiftDown(uint16_t topValue)
63 | {
64 | uint8_t *p = tlc_GSData + NUM_TLCS * 24 - 2;
65 | uint16_t zeroValue =
66 | ((uint16_t)(*(tlc_GSData + NUM_TLCS * 24 - 2) & 0x0F) << 8)
67 | | *(tlc_GSData + NUM_TLCS * 24 - 1);
68 | while (p > tlc_GSData) {
69 | *(p + 1) = (*p >> 4) | (*(p - 1) << 4);
70 | *p = (*(p - 1) >> 4) | (*(p - 2) << 4);
71 | p -= 2;
72 | }
73 | *(tlc_GSData + 1) = (*tlc_GSData >> 4) | ((uint8_t)topValue << 4);
74 | *tlc_GSData = topValue >> 4;
75 | return zeroValue;
76 | }
77 |
78 | /* @} */
79 |
80 | #endif
81 |
82 |
--------------------------------------------------------------------------------