Simple single-color 8x8x8 LED Cube with AVRs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

animations.c 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * animations.c
  3. *
  4. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  5. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  6. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  7. *
  8. * This file is part of LED-Cube.
  9. *
  10. * LED-Cube is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * LED-Cube is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. #include <stdint.h>
  24. #include <stdlib.h>
  25. #include <avr/io.h>
  26. #include <avr/wdt.h>
  27. #include <buffhelp.h>
  28. #include <cube.h>
  29. /*
  30. HOW TO Write a new Animation
  31. A) Think of a name, create a function Prototype right below this comment.
  32. B) Increment NUMOFANIMATION by the number of animations you are going to add.
  33. C) Put a function pointer to your new animation into the animations[] Array.
  34. D) Implement your animation!
  35. --> Get a buffer with buffNew(); Display it with setImage(); Free Buffer after usage!
  36. */
  37. // Prototypes for all animations
  38. void simpleAnimationA(void);
  39. void simpleAnimationB(void);
  40. void simpleAnimationC(void);
  41. void simpleAnimationD(void);
  42. void simpleAnimationE(void);
  43. void simpleAnimationF(void);
  44. // Array of animation functions
  45. #define NUMOFANIMATIONS 6
  46. void (*animations[NUMOFANIMATIONS])(void) = { &simpleAnimationA, &simpleAnimationB,
  47. &simpleAnimationC, &simpleAnimationD, &simpleAnimationE,
  48. &simpleAnimationF };
  49. #define WAVELENGTH 2
  50. uint8_t numOfAnimations(void) {
  51. return NUMOFANIMATIONS;
  52. }
  53. void executeAnimation(uint8_t id) {
  54. if (id < NUMOFANIMATIONS) {
  55. animations[id](); // Call animation
  56. }
  57. }
  58. void simpleAnimationA(void) {
  59. uint8_t *buff;
  60. int8_t x, y, z;
  61. buff = buffNew();
  62. // Up-wave
  63. for(y = 0; y < 8; y++) {
  64. for(x = 0; x < 8; x++) {
  65. for(z = 0; z < 8; z++) {
  66. buffSetPixel(buff, x, y, z);
  67. }
  68. }
  69. setImage(buff);
  70. while(isFinished() < WAVELENGTH) {
  71. wdt_reset();
  72. }
  73. buffClearAllPixels(buff);
  74. }
  75. free(buff);
  76. }
  77. void simpleAnimationB(void) {
  78. uint8_t *buff;
  79. int8_t x, y, z;
  80. buff = buffNew();
  81. // Down-wave (Frames 9-15 of showoff.cube)
  82. for(y = 7; y >= 0; y--) {
  83. for(x = 0; x < 8; x++) {
  84. for(z = 0; z < 8; z++) {
  85. buffSetPixel(buff, x, y, z);
  86. }
  87. }
  88. setImage(buff);
  89. while(isFinished() < WAVELENGTH) {
  90. wdt_reset();
  91. }
  92. buffClearAllPixels(buff);
  93. }
  94. free(buff);
  95. }
  96. void simpleAnimationC(void) {
  97. uint8_t *buff;
  98. int8_t x, y, z;
  99. buff = buffNew();
  100. // x-axis wave
  101. for(x = 0; x < 8; x++) {
  102. for(y = 0; y < 8; y++) {
  103. for(z = 0; z < 8; z++) {
  104. buffSetPixel(buff, x, y, z);
  105. }
  106. }
  107. setImage(buff);
  108. while(isFinished() < WAVELENGTH) {
  109. wdt_reset();
  110. }
  111. buffClearAllPixels(buff);
  112. }
  113. free(buff);
  114. }
  115. void simpleAnimationD(void) {
  116. uint8_t *buff;
  117. int8_t x, y, z;
  118. buff = buffNew();
  119. for(x = 7; x >= 0; x--) {
  120. for(y = 0; y < 8; y++) {
  121. for(z = 0; z < 8; z++) {
  122. buffSetPixel(buff, x, y, z);
  123. }
  124. }
  125. setImage(buff);
  126. while(isFinished() < WAVELENGTH) {
  127. wdt_reset();
  128. }
  129. buffClearAllPixels(buff);
  130. }
  131. free(buff);
  132. }
  133. void simpleAnimationE(void) {
  134. uint8_t *buff;
  135. int8_t x, y, z;
  136. buff = buffNew();
  137. // z-axis-wave
  138. for(z = 0; z < 8; z++) {
  139. for(y = 0; y < 8; y++) {
  140. for(x = 0; x < 8; x++) {
  141. buffSetPixel(buff, x, y, z);
  142. }
  143. }
  144. setImage(buff);
  145. while(isFinished() < WAVELENGTH) {
  146. wdt_reset();
  147. }
  148. buffClearAllPixels(buff);
  149. }
  150. free(buff);
  151. }
  152. void simpleAnimationF(void) {
  153. uint8_t *buff;
  154. int8_t x, y, z;
  155. buff = buffNew();
  156. for(z = 7; z >= 0; z--) {
  157. for(x = 0; x < 8; x++) {
  158. for(y = 0; y < 8; y++) {
  159. buffSetPixel(buff, x, y, z);
  160. }
  161. }
  162. setImage(buff);
  163. while(isFinished() < WAVELENGTH) {
  164. wdt_reset();
  165. }
  166. buffClearAllPixels(buff);
  167. }
  168. free(buff);
  169. }