Step 5Adjusting the software
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 Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|
















































