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.

Minidot 2 - The holoclock

Step 3Dimming algorithm - the cross fade effect and double buffering

Dimming algorithm - the cross fade effect and double buffering
The transition between one pattern and the next was previously immediate. For this clock I wanted to show one pattern gradually decreasing in brightness and the next pattern gradually increasing...ie a cross fade.

I didn't need to have individual LEDs to be controlled at seperate brightness levels to do a cross fade. Just needed the first pattern at one brightness and the second at a low brightness. Then over a short period I'd decrease the brightness of the first a little, and increase the second.....this would keep going until the second pattern as at full. Then the clock would wait till the next pattern was due to show and there would be another transition.

Thus I needed to store two patterns. The one currently being displayed and the second pattern which was about to be displayed. These are in arrays nLedsA[] and nLedsB. (note nothing to do with ports in this case). This is the double buffer.

The update_display() function was modified to cycle through eight frames and show a number of frames from first one array, then the other. Changing the number of frames allocated to each buffer throughout the eight cycles defined how bright each pattern would be. When we finished cycling between buffers we switched the 'display' and 'next display' buffers around, so the pattern generating function would then write only to the 'next display' buffer.

The diagram below shows this hopefully. You should be able to see that the transition will take 64 scan frames. In the picture, the little inset shows the scan fram diagram from the previous page artfully scaled down.

A word on re-fresh rate. All this needs to be done very quickly. We have now two levels of extra computation, one for the ambient display dimmness and one for the eight frame cycles spent doing a transition between two buffers. Thus this code was should be written in assembly, but is good enough in 'C'.

« 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!
26
Followers
7
Author:rgbphil
update later