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 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. void simpleAnimationG(void);
  45. void simpleAnimationH(void);
  46. void simpleAnimationI(void);
  47. void simpleAnimationJ(void);
  48. // Array of animation functions
  49. #define NUMOFANIMATIONS 10
  50. void (*animations[NUMOFANIMATIONS])(void) = { &simpleAnimationA, &simpleAnimationB,
  51. &simpleAnimationC, &simpleAnimationD, &simpleAnimationE,
  52. &simpleAnimationF, &simpleAnimationG, &simpleAnimationH, &simpleAnimationI, &simpleAnimationJ };
  53. #define WAVELENGTH 2
  54. uint8_t numOfAnimations(void) {
  55. return NUMOFANIMATIONS;
  56. }
  57. void executeAnimation(uint8_t id) {
  58. if (id < NUMOFANIMATIONS) {
  59. animations[id](); // Call animation
  60. }
  61. }
  62. void simpleAnimationA(void) {
  63. uint8_t *buff;
  64. int8_t x, y, z;
  65. buff = buffNew();
  66. // Up-wave
  67. for(y = 0; y < 8; y++) {
  68. for(x = 0; x < 8; x++) {
  69. for(z = 0; z < 8; z++) {
  70. buffSetPixel(buff, x, y, z);
  71. }
  72. }
  73. setImage(buff);
  74. while(isFinished() < WAVELENGTH) {
  75. wdt_reset();
  76. }
  77. buffClearAllPixels(buff);
  78. }
  79. free(buff);
  80. }
  81. void simpleAnimationB(void) {
  82. uint8_t *buff;
  83. int8_t x, y, z;
  84. buff = buffNew();
  85. // Down-wave (Frames 9-15 of showoff.cube)
  86. for(y = 7; y >= 0; y--) {
  87. for(x = 0; x < 8; x++) {
  88. for(z = 0; z < 8; z++) {
  89. buffSetPixel(buff, x, y, z);
  90. }
  91. }
  92. setImage(buff);
  93. while(isFinished() < WAVELENGTH) {
  94. wdt_reset();
  95. }
  96. buffClearAllPixels(buff);
  97. }
  98. free(buff);
  99. }
  100. void simpleAnimationC(void) {
  101. uint8_t *buff;
  102. int8_t x, y, z;
  103. buff = buffNew();
  104. // x-axis wave
  105. for(x = 0; x < 8; x++) {
  106. for(y = 0; y < 8; y++) {
  107. for(z = 0; z < 8; z++) {
  108. buffSetPixel(buff, x, y, z);
  109. }
  110. }
  111. setImage(buff);
  112. while(isFinished() < WAVELENGTH) {
  113. wdt_reset();
  114. }
  115. buffClearAllPixels(buff);
  116. }
  117. free(buff);
  118. }
  119. void simpleAnimationD(void) {
  120. uint8_t *buff;
  121. int8_t x, y, z;
  122. buff = buffNew();
  123. for(x = 7; x >= 0; x--) {
  124. for(y = 0; y < 8; y++) {
  125. for(z = 0; z < 8; z++) {
  126. buffSetPixel(buff, x, y, z);
  127. }
  128. }
  129. setImage(buff);
  130. while(isFinished() < WAVELENGTH) {
  131. wdt_reset();
  132. }
  133. buffClearAllPixels(buff);
  134. }
  135. free(buff);
  136. }
  137. void simpleAnimationE(void) {
  138. uint8_t *buff;
  139. int8_t x, y, z;
  140. buff = buffNew();
  141. // z-axis-wave
  142. for(z = 0; z < 8; z++) {
  143. for(y = 0; y < 8; y++) {
  144. for(x = 0; x < 8; x++) {
  145. buffSetPixel(buff, x, y, z);
  146. }
  147. }
  148. setImage(buff);
  149. while(isFinished() < WAVELENGTH) {
  150. wdt_reset();
  151. }
  152. buffClearAllPixels(buff);
  153. }
  154. free(buff);
  155. }
  156. void simpleAnimationF(void) {
  157. uint8_t *buff;
  158. int8_t x, y, z;
  159. buff = buffNew();
  160. for(z = 7; z >= 0; z--) {
  161. for(x = 0; x < 8; x++) {
  162. for(y = 0; y < 8; y++) {
  163. buffSetPixel(buff, x, y, z);
  164. }
  165. }
  166. setImage(buff);
  167. while(isFinished() < WAVELENGTH) {
  168. wdt_reset();
  169. }
  170. buffClearAllPixels(buff);
  171. }
  172. free(buff);
  173. }
  174. void simpleAnimationG(void) {
  175. uint8_t *buff;
  176. int8_t x, y, z;
  177. buff = buffNew();
  178. //Cube_1
  179. buffSetPixel(buff, 3, 3, 3);
  180. buffSetPixel(buff, 4, 3, 3);
  181. buffSetPixel(buff, 4, 4, 3);
  182. buffSetPixel(buff, 4, 4, 4);
  183. setImage(buff);
  184. while(isFinished() < WAVELENGTH) {
  185. wdt_reset();
  186. }
  187. buffClearAllPixels(buff);
  188. free(buff);
  189. }
  190. void simpleAnimationH (void){
  191. uint8_t *buff;
  192. int8_t x, y, z;
  193. buff = buffNew();
  194. //Cube_2
  195. for(x = 2; x < 6; x++) {
  196. for(y = 2; y < 6; y++) {
  197. buffSetPixel(buff, x, y, 2);
  198. buffSetPixel(buff, x, y, 5);
  199. }
  200. }
  201. for(y = 2; y < 6; y++) {
  202. for(z = 2; z < 6; z++) {
  203. buffSetPixel(buff, 2, y, z);
  204. buffSetPixel(buff, 5, y, z);
  205. }
  206. }
  207. for(x = 2; x < 6; x++) {
  208. for(z = 2; z < 6; z++) {
  209. buffSetPixel(buff, x, 2, z);
  210. buffSetPixel(buff, x, 5, z);
  211. }
  212. }
  213. setImage(buff);
  214. while(isFinished() < WAVELENGTH) {
  215. wdt_reset();
  216. }
  217. buffClearAllPixels(buff);
  218. free(buff);
  219. }
  220. void simpleAnimationI (void) {
  221. uint8_t *buff;
  222. int8_t x, y, z;
  223. buff = buffNew();
  224. //Cube_3
  225. for(x = 1; x < 7; x++){
  226. for(y = 1; y < 7; y++) {
  227. buffSetPixel(buff, x, y, 1);
  228. buffSetPixel(buff, x, y, 6);
  229. }
  230. }
  231. for(y = 1; y < 7; y++){
  232. for(z = 1; z < 7; z++) {
  233. buffSetPixel(buff, 1, y, z);
  234. buffSetPixel(buff, 6, y, z);
  235. }
  236. }
  237. for(x = 1; x < 7; x++){
  238. for(z = 1; z < 7; z++) {
  239. buffSetPixel(buff, x, 1, z);
  240. buffSetPixel(buff, x, 6, z);
  241. }
  242. }
  243. setImage(buff);
  244. while(isFinished() < WAVELENGTH) {
  245. wdt_reset();
  246. }
  247. buffClearAllPixels(buff);
  248. free(buff);
  249. }
  250. void simpleAnimationJ (void) {
  251. uint8_t *buff;
  252. int8_t x, y, z;
  253. buff = buffNew();
  254. //Cube_4
  255. for(x = 0; x < 8; x++){
  256. for(y = 0; y < 8; y++) {
  257. buffSetPixel(buff, x, y, 0);
  258. buffSetPixel(buff, x, y, 7);
  259. }
  260. }
  261. for(y = 0; y < 8; y++){
  262. for(z = 0; z < 8; z++) {
  263. buffSetPixel(buff, 0, y, z);
  264. buffSetPixel(buff, 8, y, z);
  265. }
  266. }
  267. for(x = 0; x < 8; x++){
  268. for(z = 0; z < 8; z++) {
  269. buffSetPixel(buff, x, 0, z);
  270. buffSetPixel(buff, x, 8, z);
  271. }
  272. }
  273. setImage(buff);
  274. while(isFinished() < WAVELENGTH) {
  275. wdt_reset();
  276. }
  277. buffClearAllPixels(buff);
  278. free(buff);
  279. }