We made two field animation capabilities for the LED dice. Effect_box_shrink_grow() attracts a wireframe field filling the complete dice, then shrinks it down to at least one voxel in considered one of Eight corners. We name this perform one time for every of the Eight corners to create a pleasant impact. Effect_box_woopwoop() attracts a field that begins as a 8x8x8 wireframe field filling the complete dice. It then shrinks all the way down to a 2x2x2 field on the middle of the dice. Or in reverse if develop is specified.
Here is how effect_box_shrink_grow() works.
It takes 4 arguments, variety of iterations, rotation, flip and delay. Rotation specifies rotation across the Z axis at 90 diploma intervals. Flip > Zero flips the dice upside-down.
To make the perform so simple as potential, it simply attracts a field from Zero,Zero,Zero to any level alongside the diagonal between Zero,Zero,Zero and seven,7,7 then makes use of axis mirror capabilities from draw.c to rotate it.
1) Enter important iteration loop.
2) Enter a for() loop going from Zero to 15.
Three) Set xyz to 7-i. This makes xyz the reverse of i. We wish to shrink the field first, then develop. xyz is the purpose alongside the diagonal. We simply used one variable since x, y and z are all equal alongside this diagonal.
Four) When i = 7, the field has shrunk to a 1x1x1 field, and we won’t shrink it any extra. If i is bigger than 7, xyz is about to i-Eight, which makes xyz journey from Zero to 7 when i travels from Eight to 15. We did this trick to keep away from having two for loops, whith one going from 7-Zero and one from Zero-7.
5) Blank the dice and delay a bit bit to ensure the blanking is rendered on the dice. Disable the interrupt routine. We do that as a result of the mirror capabilities takes a bit time. Without disabling interrupts, the wireframe field would flash briefly within the authentic rotation earlier than being displayed rotated.
6) Draw the wireframe field in its authentic rotation. facet of the field is all the time at Zero,Zero,Zero whereas the opposite travels alongside the diagonal.
7) Do the rotations. If flip is greather than Zero, the dice is turned upside-down. rot takes a quantity from Zero to three the place Zero is Zero levels of rotation round Z and three is 270 levels. To get 270 levels we merely mirror round X and Y.
Eight) Enable interrupts to show the now rotated dice.
9) Delay for some time then clear the dice.
The different perform concerned within the wireframe field impact is effect_box_woopwoop(). The identify woopwoop simply sounded pure once we first noticed the impact rendered on the dice 😉
The woopwoop perform solely does one iteration and takes two arguments, delay and develop. If develop is bigger than Zero, the field begins as a 2x2x2 field and develop to a 8x8x8 field.
Here is the way it works:
1) Clear the dice by filling the buffer with 0x00;
2) For()-loop from Zero to three.
Four) Set ii to i. If develop is specified we set it to Three-i to reverse it.
5) Draw a wireframe field centered alongside the diagonal between Zero,Zero,Zero and seven,7,7. One nook of the field makes use of the coordinates Four+ii on all axes, transferring from Four-7. The different nook makes use of Three-ii on all axes, transferring from Three-Zero.
6) Delay for some time, then clear the dice.
These two capabilities are used as one single impact within the impact launcher. First the shrink develop impact is known as Eight occasions, one for every nook, then woopwoop is known as 4 occasions, two shrink and develop cycles.
To launch the shrink develop perform, we used a for loop with some neat bit manipulation tips inside to keep away from writing Eight strains of code.
The second argument of the shrink develop capabilities is the rotation, in Four steps. We are counting from Zero to 7, so we won’t merely feed i into the perform. We use the modulo operator % to maintain the quantity inside a spread of Zero-Four. The modulo operator divides by the quantity specifies and returns the rest.
The third argument is the flip. When flip = Zero, the dice just isn’t flipped. > Zero flips. We use the bitwise AND operator to solely learn bit Three of i.
Bitwise operators are an absolute should to learn about when working with micro controllers, however that’s outdoors the scope of this instructable. The guys over at AVR Freaks have posted some nice details about this matter. You can learn extra at http://www.avrfreaks.web/index.php?identify=PNphpBB2&file=viewtopic&t=37871