Simple single-color 8x8x8 LED Cube with AVRs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

animations.c 5.7KB

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