3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Ghostbusters Proton Pack with Arduino and LASERS!

Step 3Program the Arduino

Program the Arduino
I am very new at this whole microcontroller thing, so I'm sure all of you veterans out there could have written a much more elegant piece of code for this.  My simplistic idea for how to make this work does however have the advantage of being both very easy to understand by the uninitiated and very simple to change if you want to alter the way the lights flash.

The basic concept behind the code is that it runs a loop 6.4 seconds long, broken into 64 100 millisecond "ticks."  At each tick, I can have a light turn on, turn off, dim, brighten, etc.  After it's gone through it all once, it goes right back to the beginning and repeats until the battery runs out.

« Previous StepDownload PDFView All StepsNext Step »
3 comments
Dec 24, 2009. 8:58 PMscgtrp says:
Some comments on the code: I recommend using meaningful names for the pins rather than just saying "six is 6!" in which case you might as well just skip that part and do analogWrite(6, 220);. Also, #define FADING_LED 6 is the usual way to do it in real C, and will save a small amount of memory by directly inserting 6 in place of FADING_LED at compile time rather than storing it in a separate variable. (Actually, depending on the way the Arduino IDE compiles the code it may be optimized to that anyway, but I can't say for sure.)

loop() will take a bit longer than 6.4 seconds because digitalWrite/analogWrite take time too, but I can't see that making a difference in this case given that you're just making pretty effects with LEDs rather than controlling some ultra-precise piece of equipment. Just letting you know, for future reference.

Other than my general pickiness about code, I must say that's rather pretty :)
Dec 25, 2009. 1:14 PMscgtrp says:
Right, I just checked it out and #define TEST 1 vs int test = 1; actually do generate a binary of the same size. The difference is that you can't accidentally change it later with the first one, which can help prevent bugs.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
306
Followers
54
Author:depotdevoid(depotdevoid on Facebook!)
Like me on Facebook, my poor, fragile ego needs a boost! I post updates about my current projects, and the occasional sneak peak at upcoming instructables! ...
more »