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.

Darth Maul LED light saber

Step 4Programming the PIC

The great thing about programming the Picaxe is the minimal amount of money you need to get into using them and the simplicity of the language. For my program I used about 1/2 dozen BASIC commands. Experts could probably do more for less but I'm a hack and get a result that suits me! To program the chip itself you need a chip (obviously) A download cable - serial or parallel you could even make serial one your self for next to nothing, also you will need the free programming software available on the Picaxe website.

The Picaxe I used was an 18X, this chip has 9 output pins and 5 input pins and can hold up to 600 lines of code. At this stage I only make use of the 6 of the output pins. 5 to run the LED's and 1 to turn on and off the sound module. At a later stage I could break the LED's up into 8 blocks for a higher resolution, remember my darlington driver can run up to 8 outputs at once. Or alternatively I could make the blade up of 4 blocks (Like another brand) and control each blade individually

All that said and done I can pretty much make the blades light up and down with about 20 lines of code. So what about the other 580? This seems a waste so I have added some extra modes 1. Normal mode, 2. Normal mode no sound 3. Night Rider mode 5. Pig mode. To change modes you hold down the push button for 5 seconds the saber flashes twice to signify program mode and depending on how many times you hit the push button with in 5 seconds dictates your new mode. If you don't press the button or press it too many times it reverts back to normal mode.

Here is the code that I have started with anyway.....

b5 = %00000001 ' Intiallise saber mode variable
b1 =0 ' Intialise mode change counter variable
b0 =0 ' Not sure why I did this
b2 = 1 ' Set the default mode to Saber normal

let pins = %00100000 ' Set pin 6 HIGH, LOW will turn on the sound module

Reset: ' resets all the pins after a mode change
let pins = %00100000
pause 100
goto loop

loop: ' main loop checking push button
if pin2 = 0 then mode ??? jump to flsh if pin0 is high
goto loop

mode:
if b1 > 5 then mode_change ' if the counter is at 5 goto mode change
pause 20
if pin2 = 1 then decide ' if the switch is up goto select a mode
if pin2 = 0 then count_t ' goto counter
count_t: ' this counter will count to five
pause 10
b1=b1+1
goto mode

mode_change: ' flashes saber twice to signify mode change
b2 = 0
let pins = %00111111
pause 300
let pins = %00100000
pause 300
let pins = %00111111
pause 300
let pins = %00100000
pause 300

count 2, 5000, b2 'counts bush button actions with in 5 seconds and stores this in b2
let pins = %00111111
pause 300
let pins = %00100000
pause 300
b1 = 0
goto loop

Decide: ' decision made depending on value in b2
b1=0
if b2 = 1 then saber
if b2 = 2 then silent_saber
if b2 = 3 then Knight_rider
if b2 = 4 then pigs
if b2 > 4 then saber
if b2 < 1 then saber
goto loop

saber: ' basic saber mode
b1 = 0
if b5 != %00000001 then p_down
if b5 = %00000001 then p_up
goto loop

p_up:
let pins = %00110000
pause 200
let pins = %00010000
pause 100
let pins = %00011000
pause 100
let pins = %00011100
pause 100
let pins = %00011110
pause 100
let pins = %00011111
b5 = %00000000

goto loop

p_down:
let pins = %00111111
pause 200
let pins = %00011111
pause 400
let pins = %00011111
pause 100
let pins = %00011110
pause 100
let pins = %00011100
pause 100
let pins = %00011000
pause 100
let pins = %00010000
pause 100
let pins = %00000000
b5 = %00000001

goto loop

silent_saber: ' says it all really
b1 = 0
if b5 != %00000001 then p_down_s
if b5 = %00000001 then p_up_s
goto loop

p_up_s:
let pins = %00110000
pause 100
let pins = %00111000
pause 100
let pins = %00111100
pause 100
let pins = %00111110
pause 100
let pins = %00111111
b5 = %00000000

goto loop

p_down_s:
let pins = %00111111
pause 100
let pins = %00111110
pause 100
let pins = %00111100
pause 100
let pins = %00111000
pause 100
let pins = %00110000
pause 100
let pins = %00100000
b5 = %00000001

goto loop

Knight_rider:
if pin2 = 0 then reset
let pins = %00100000
pause 100
let pins = %00110000
pause 100
let pins = %00101000
pause 100
let pins = %00100100
pause 100
if pin2 = 0 then reset
let pins = %00100010
pause 100
let pins = %00100001
pause 100
let pins = %00100010
if pin2 = 0 then reset
pause 100
let pins = %00100100
pause 100
let pins = %00101000
pause 100
let pins = %00110000
if pin2 = 0 then reset
goto Knight_rider

pigs:
if pin2 = 0 then reset
let pins = %00100000
pause 100
let pins = %00110000
pause 100
let pins = %00101000
pause 100
let pins = %00100100
pause 100
if pin2 = 0 then reset
let pins = %00100010
pause 100
let pins = %00100001
if pin2 = 0 then reset
goto pigs

Eventually I think it would be cool to use a microphone or something and use the saber as a VU meter - Bring on the tri colour LED's!
« Previous StepDownload PDFView All StepsNext Step »
1 comment

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!
2
Followers
2
Author:jmumby