To update items that are difficult to calculate any other way, to bring objects to life, to make objects respond to values around them, height, length, time, sound, beats, etc...
I have done it in animations for a number of reasons:
This article describes the last one, to display numbers on a seven segment display corresponding to elapsed seconds and frames. The display shows seconds to the left of the decimal point, and current number of frames in the last second to the right.
You could just as easily show any numerical parameter, seconds, frame number, some other value from the scene etc.
To make use of the example, download and install Blender(the example was tested with V5.01), and download the example file, Blender-8CharArrayOf7-segmentV1-4.zip. Unpack the zip file in a convenient place, it contains the Blender file, 8CharArrayOf7-segmentV1-2.blend, and the python script, LEDDisplayControlV1-3.py. And open the Blender file.
Go to "Layout" in the example file, and turn on Cycles rendering. You should see an eight digit 7-segment display with red LED segments.
|
It operates in the same way as a "physical" display, each digit is a block of opaque black
plastic with eight translucent plastic inserts, one per segment plus the decimal point. Select
"wireframe" view to see the segment structure. At the back of the segments is an LED chip, in Blender terms a red cylinder made of a high emission material. When the LED is ON its x and y dimensions are 0.001 m and it is visible. When it is OFF its x and y dimensions are 0.0 m, and it is too small to see. Numbers and symbols are displayed when the correct combination of LED segments is ON. |
|
Select the Scripting tab. The python script LEDDisplayControlV1-3.py should be run before viewing/rendering the animation by pressing the "Play" icon at the top of the script panel.
The script initializes a handler that runs the function "SevenSegmentLEDarrayControl" before rendering each frame of the animation.
When "SevenSegmentLEDarrayControl" runs, it converts a value in text form, "valuetext", to the pattern of LED segments needed to display a number.
In this script the LED array displays elapsed whole seconds left of the decimal point, and the number of frames since the last second on the right.
The function "createValueText" could be changed to present any other value to the LED array.
The first thing to run when the script is started is the MAIN function. MAIN first checks to see if there is already a handler running for "SevenSegmentLEDarrayControl". If so the handler is stopped before starting up a new instance. MAIN also constructs the python list "LEDEmitters" that contains names of the LED emitter objects in the LED array. This is used in "updateSegments" to turn individual segment LEDs ON and OFF.
At each frame change SevenSegmentLEDarrayControl runs, it calls createValueText to gather information required to set up the value to be displayed, and then calls updateSegments to change the value on the display.
The video walkthru shows:
The seven segments in a 7-segment LED display are usually identified as shown in the diagram as segments "A" thru "G".
| --A-- | ||
| | | | ||
| F B | ||
| | | | ||
| --G-- | ||
| | | | ||
| E C | ||
| | | | ||
| --D-- |
The combinations of segments used to show each number
are shown in the table below along with the binary representation, and the decimal number used to display each
digit in the code.
Note: It is also possible to represent some Alpha characters with the seven segments, for example, A,
C, E, F, etc...
| 0 | = | ABCDEF | = | 00111111 | = | 63 |
| 1 | = | BC | = | 00000110 | = | 6 |
| 2 | = | AB DE G | = | 01011011 | = | 91 |
| 3 | = | ABCD G | = | 01001111 | = | 79 |
| 4 | = | BC FG | = | 01100110 | = | 102 |
| 5 | = | A CD FG | = | 01101101 | = | 109 |
| 6 | = | A CDEFG | = | 01111101 | = | 125 |
| 7 | = | ABC | = | 00000111 | = | 7 |
| 8 | = | ABCDEFG | = | 01111111 | = | 127 |
| 9 | = | ABCD FG | = | 01101111 | = | 111 |
In the segment list below, the element index is the digit, the value is from the segment map above.
| Index/digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| segmentlist | = | [ | 63, | 6, | 91, | 79, | 102, | 109, | 125, | 7, | 127, | 111 | ] |
For example, the digit 7 requires that segments A, B, and C are illuminated, and that all others
are OFF. ABC are the first three digits, that is 00000111 in binary = 7 in decimal.
In the python script the array "segmentlist" contains each of the decimal values for each digit, 0..9,
the index to the array is the digit to be displayed.
Here is another example of video using python scripts that update data at each frame, you might like to unmute the audio and restart!:
The LED bargraph displays are similar in construction to the LED array in this article. They are driven by an
amplitude file created from the audio.
The metronome is driven by a beat file created by hand from the audio. It changes speed according to the tempo
in the beat file.
In both cases, the python script works out what response is needed to the inputs and drives animation parameters
accordingly, brightness for the LEDs and physical position for the arm and the weight of the metronome.
If you would like more information about this example please get in touch via comments@chisholm.nl
The soundtrack is the recording that I made some years ago of, "Dawn of a new of a new life" by Cycle, see https://chisholm.nl/cycle/cycle.html. The track was published in 2020 on an album from Rise Above Records Ltd., at https://riseaboverecords.com/product/cosmic-clouds/.