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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 <avr/io.h>
  25. #include <avr/wdt.h>
  26. #include <buffhelp.h>
  27. #include <cube.h>
  28. // Prototypes for all animations
  29. void simpleAnimation(void);
  30. void anotherAnimation(void);
  31. // Array of animation functions
  32. #define NUMOFANIMATIONS 2
  33. void (*animations[NUMOFANIMATIONS])(void) = {&simpleAnimation, &anotherAnimation};
  34. uint8_t numOfAnimations(void) {
  35. return NUMOFANIMATIONS;
  36. }
  37. void executeAnimation(uint8_t id) {
  38. if (id < NUMOFANIMATIONS) {
  39. animations[id](); // Call animation
  40. }
  41. }
  42. void simpleAnimation(void) {
  43. uint8_t *buff;
  44. int8_t x, y, z, i;
  45. buff = buffNew();
  46. //Up-wave
  47. for(i = 0; i < 3; i++) { //Display frame 3/24 seconds
  48. for(y = 0; y < 8; y++) {
  49. for(x = 0; x < 8; x++) {
  50. for(z = 0; z < 8; z++) {
  51. buffSetPixel(buff, x, y, z);
  52. }
  53. }
  54. setImage(buff);
  55. while(!isFinished()) {
  56. wdt_reset();
  57. }
  58. buffClearAllPixels(buff);
  59. }
  60. }
  61. // Down-wave (Frames 9-15 of showoff.cube)
  62. for(i = 0; i < 3; i++) {
  63. for(y = 7; y >= 0; y--) {
  64. for(x = 0; x < 8; x++) {
  65. for(z = 0; z < 8; z++) {
  66. buffSetPixel(buff, x, y, z);
  67. }
  68. }
  69. setImage(buff);
  70. while(!isFinished()) {
  71. wdt_reset();
  72. }
  73. buffClearAllPixels(buff);
  74. }
  75. }
  76. //x-axis wave
  77. for(i = 0; i < 3; i++){
  78. for(x = 0; x < 8; x++) {
  79. for(y = 0; y < 8; y++) {
  80. for(z = 0; z < 8; z++) {
  81. buffSetPixel(buff, x, y, z);
  82. }
  83. }
  84. setImage(buff);
  85. while(!isFinished()) {
  86. wdt_reset();
  87. }
  88. buffClearAllPixels(buff);
  89. }
  90. for(x = 7; x >= 0; x--) {
  91. for(y = 0; y < 8; y++) {
  92. for(z = 0; z < 8; z++) {
  93. buffSetPixel(buff, x, y, z);
  94. }
  95. }
  96. setImage(buff);
  97. while(!isFinished()) {
  98. wdt_reset();
  99. }
  100. buffClearAllPixels(buff);
  101. }
  102. }
  103. //z-axis-wave
  104. for(i = 0; i < 3; i++) {
  105. for(z = 0; z < 8; z++) {
  106. for(y = 0; y < 8; y++) {
  107. for(x = 0; x < 8; x++) {
  108. buffSetPixel(buff, x, y, z);
  109. }
  110. }
  111. setImage(buff);
  112. while(!isFinished()) {
  113. wdt_reset();
  114. }
  115. buffClearAllPixels(buff);
  116. }
  117. for(z = 7; z >= 0; z--) {
  118. for(x = 0; x < 8; x++) {
  119. for(y = 0; y < 8; y++) {
  120. buffSetPixel(buff, x, y, z);
  121. }
  122. }
  123. setImage(buff);
  124. while(!isFinished()) {
  125. wdt_reset();
  126. }
  127. buffClearAllPixels(buff);
  128. }
  129. }
  130. }
  131. void anotherAnimation(void) {
  132. }