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.

A sunrise and sunset lamp with LEDs

Step 5Adjusting the software

Adjusting the software
«
  • 05a Sunset.JPG
  • 05b Sunrise 1.jpg
The picaxes are very easy programmable by some basic dialect from the vendor. The Editor and the software are free of charge. Of course one might also program this in assembler for blank PICs or for the Atmel AVRs, but this was one of my first projects after I tested the picaxes. In the meantime I work on a better version with several PWMs on an AVR.

The picaxes are very good for beginners because the requirements to the hardware are very simple and the basic-language is easy to learn. With less than 30€ you can start to explore the wonderful world of microcontrollers. The disadvantage of this cheap chip (18M) is the limited RAM.
If you chose other features or connect the picaxe different you might have to adjust the program. But surely you will have to make adjustments to the transitions between the individuals strips.

As you can see in the listing the variable w6 (a word-variable) acts as a counter – variable and as the parameter for the PWM. With the chosen PWM-frequency of 4kHz the values for 1% to 99% duty-time are 10 to 990 respectively. With the calculations in the loop we get a nearly exponential decrease or increase of LED-brightness. This is the optimal when you control LEDs with PWM. When switching on or off one strip, this is compensated by the software by changing the value of the PWM.

For example let's look at the sunset. Initially the outputs 0,  4 and 5 are switched high, that means the respective strips are switched on via the ULN2803A. Then the loop reduced brightness until the variable in w6 is smaller than 700. At this point pin0 is switched low and pin2 is switched high. The new value of w6 is set to 900.
This means that the lamp with strips 0, 4 and 5 at PWM-level 700 is nearly as bright as the lamp with strips 2, 4 and 5 at PWM-level 800. To find out these values you have to test around and try some different values. Try to stay somewhere in the middle, because when you dim down the lamp in the first loop too much, you can not make much in the second loop. This will reduce the colour-change-effect.

To adjust the PWM-settings I used a subroutine that also uses the value of w5 to pause the program. At this point the speed comes in the game. Only during start-up the potentiometer is checked and the value is stored in w5. The number of steps in each loop of the program are fixed, but by changing the value of w5 from 750 to around 5100, the pause in each step changes from 0.75s to 5s.

The number of steps in each loop might also be adjusted by changing the fraction for the exponential de- or increase. But make sure not to use to small fractions, because the variable w6 is always a whole number! If you would use 99/100 as a fraction and apply that to a value of 10, that would give you 9.99 in decimals but again 10 in integers. Also keep in mind that w6 might not exceed 65325!

To speed up testing, try to comment out the line with w5 = 5*w5, this will speed up the program by a factor of 5! :-)
« Previous StepDownload PDFView All StepsNext Step »

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!
49
Followers
22
Author:andyk75
I like to explorer new things and try out stuff. At the moment I'm in to electronics and LEDs (mainly).