Simple single-color 8x8x8 LED Cube with AVRs
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

animations.c 3.5KB

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