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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. --> Return desired duration until the next animation is called, in frames (24fps)
  37. */
  38. // Prototypes for all animations
  39. void upWave(uint8_t i);
  40. void downWave(uint8_t i);
  41. void zWave1(uint8_t i);
  42. void zWave2(uint8_t i);
  43. // Array of animation functions
  44. #define NUMOFANIMATIONS 0
  45. uint8_t (*animations[NUMOFANIMATIONS])(void) = { };
  46. #define WAVELENGTH 1
  47. uint8_t numOfAnimations(void) {
  48. return NUMOFANIMATIONS + (4*4);
  49. }
  50. uint8_t executeAnimation(uint8_t id) {
  51. if (id < (4*4)) {
  52. if (id < 4) {
  53. zWave1(id);
  54. } else if (id < 8) {
  55. zWave2(id - 4);
  56. } else if (id < 12) {
  57. upWave(id - 8);
  58. } else if (id < 16) {
  59. downWave(id - 12);
  60. }
  61. return 1;
  62. } else if ((id - (4*4)) < NUMOFANIMATIONS) {
  63. return animations[id - (4*4)](); // Call animation
  64. }
  65. return 1;
  66. }
  67. void upWave(uint8_t i) {
  68. uint8_t *buff;
  69. int8_t x, y, z;
  70. buff = buffNew();
  71. // Up-wave
  72. for(y = (i * 2); y < ((i * 2) + 2); y++) {
  73. for(x = 0; x < 8; x++) {
  74. for(z = 0; z < 8; z++) {
  75. buffSetPixel(buff, x, y, z);
  76. }
  77. }
  78. setImage(buff);
  79. while(isFinished() < WAVELENGTH) {
  80. wdt_reset();
  81. }
  82. buffClearAllPixels(buff);
  83. }
  84. free(buff);
  85. }
  86. void downWave(uint8_t i) {
  87. uint8_t *buff;
  88. int8_t x, y, z;
  89. buff = buffNew();
  90. // Down-wave (Frames 9-15 of showoff.cube)
  91. for(y = (7 - (2 * i)); y >= ((7 - (2 * i)) - 1); y--) {
  92. for(x = 0; x < 8; x++) {
  93. for(z = 0; z < 8; z++) {
  94. buffSetPixel(buff, x, y, z);
  95. }
  96. }
  97. setImage(buff);
  98. while(isFinished() < WAVELENGTH) {
  99. wdt_reset();
  100. }
  101. buffClearAllPixels(buff);
  102. }
  103. free(buff);
  104. }
  105. void zWave1(uint8_t i) {
  106. uint8_t *buff;
  107. int8_t x, y, z;
  108. buff = buffNew();
  109. // z-axis-wave
  110. for(z = (i * 2); z < ((i * 2) + 2); z++) {
  111. for(y = 0; y < 8; y++) {
  112. for(x = 0; x < 8; x++) {
  113. buffSetPixel(buff, x, y, z);
  114. }
  115. }
  116. setImage(buff);
  117. while(isFinished() < WAVELENGTH) {
  118. wdt_reset();
  119. }
  120. buffClearAllPixels(buff);
  121. }
  122. free(buff);
  123. }
  124. void zWave2(uint8_t i) {
  125. uint8_t *buff;
  126. int8_t x, y, z;
  127. buff = buffNew();
  128. for(z = (7 - (2 * i)); z >= ((7 - (2 * i)) - 1); z--) {
  129. for(x = 0; x < 8; x++) {
  130. for(y = 0; y < 8; y++) {
  131. buffSetPixel(buff, x, y, z);
  132. }
  133. }
  134. setImage(buff);
  135. while(isFinished() < WAVELENGTH) {
  136. wdt_reset();
  137. }
  138. buffClearAllPixels(buff);
  139. }
  140. free(buff);
  141. }