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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 upWave(void);
  39. void downWave(void);
  40. void xWave1(void);
  41. void xWave2(void);
  42. void zWave1(void);
  43. void zWave2(void);
  44. void tinyCube(void);
  45. void smallCube(void);
  46. void bigCube(void);
  47. void fullCube(void);
  48. // Array of animation functions
  49. #define NUMOFANIMATIONS 10
  50. void (*animations[NUMOFANIMATIONS])(void) = { &upWave, &downWave,
  51. &xWave1, &xWave2, &zWave1,
  52. &zWave2, &tinyCube, &smallCube, &bigCube, &fullCube };
  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 upWave(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 downWave(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 xWave1(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 xWave2(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 zWave1(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 zWave2(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 tinyCube(void) {
  175. uint8_t *buff;
  176. buff = buffNew();
  177. //Cube_1
  178. buffSetPixel(buff, 3, 3, 3);
  179. buffSetPixel(buff, 4, 3, 3);
  180. buffSetPixel(buff, 4, 4, 3);
  181. buffSetPixel(buff, 4, 4, 4);
  182. setImage(buff);
  183. while(isFinished() < WAVELENGTH) {
  184. wdt_reset();
  185. }
  186. buffClearAllPixels(buff);
  187. free(buff);
  188. }
  189. void smallCube (void){
  190. uint8_t *buff;
  191. int8_t x, y, z;
  192. buff = buffNew();
  193. //Cube_2
  194. for(x = 2; x < 6; x++) {
  195. for(y = 2; y < 6; y++) {
  196. buffSetPixel(buff, x, y, 2);
  197. buffSetPixel(buff, x, y, 5);
  198. }
  199. }
  200. for(y = 2; y < 6; y++) {
  201. for(z = 2; z < 6; z++) {
  202. buffSetPixel(buff, 2, y, z);
  203. buffSetPixel(buff, 5, y, z);
  204. }
  205. }
  206. for(x = 2; x < 6; x++) {
  207. for(z = 2; z < 6; z++) {
  208. buffSetPixel(buff, x, 2, z);
  209. buffSetPixel(buff, x, 5, z);
  210. }
  211. }
  212. setImage(buff);
  213. while(isFinished() < WAVELENGTH) {
  214. wdt_reset();
  215. }
  216. buffClearAllPixels(buff);
  217. free(buff);
  218. }
  219. void bigCube (void) {
  220. uint8_t *buff;
  221. int8_t x, y, z;
  222. buff = buffNew();
  223. //Cube_3
  224. for(x = 1; x < 7; x++){
  225. for(y = 1; y < 7; y++) {
  226. buffSetPixel(buff, x, y, 1);
  227. buffSetPixel(buff, x, y, 6);
  228. }
  229. }
  230. for(y = 1; y < 7; y++){
  231. for(z = 1; z < 7; z++) {
  232. buffSetPixel(buff, 1, y, z);
  233. buffSetPixel(buff, 6, y, z);
  234. }
  235. }
  236. for(x = 1; x < 7; x++){
  237. for(z = 1; z < 7; z++) {
  238. buffSetPixel(buff, x, 1, z);
  239. buffSetPixel(buff, x, 6, z);
  240. }
  241. }
  242. setImage(buff);
  243. while(isFinished() < WAVELENGTH) {
  244. wdt_reset();
  245. }
  246. buffClearAllPixels(buff);
  247. free(buff);
  248. }
  249. void fullCube (void) {
  250. uint8_t *buff;
  251. int8_t x, y, z;
  252. buff = buffNew();
  253. //Cube_4
  254. for(x = 0; x < 8; x++){
  255. for(y = 0; y < 8; y++) {
  256. buffSetPixel(buff, x, y, 0);
  257. buffSetPixel(buff, x, y, 7);
  258. }
  259. }
  260. for(y = 0; y < 8; y++){
  261. for(z = 0; z < 8; z++) {
  262. buffSetPixel(buff, 0, y, z);
  263. buffSetPixel(buff, 8, y, z);
  264. }
  265. }
  266. for(x = 0; x < 8; x++){
  267. for(z = 0; z < 8; z++) {
  268. buffSetPixel(buff, x, 0, z);
  269. buffSetPixel(buff, x, 8, z);
  270. }
  271. }
  272. setImage(buff);
  273. while(isFinished() < WAVELENGTH) {
  274. wdt_reset();
  275. }
  276. buffClearAllPixels(buff);
  277. free(buff);
  278. }