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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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;
  45. buff = buffNew();
  46. //Up-wave
  47. for(y = 0; y < 8; y++) {
  48. for(x = 0; x < 8; x++) {
  49. for(z = 0; z < 8; z++) {
  50. buffSetPixel(buff, x, y, z);
  51. }
  52. }
  53. setImage(buff);
  54. while(!isFinished()) {
  55. wdt_reset();
  56. }
  57. buffClearAllPixels(buff);
  58. }
  59. // Down-wave (Frames 9-15 of showoff.cube)
  60. for(y = 7; y >= 0; y--) {
  61. for(x = 0; x < 8; x++) {
  62. for(z = 0; z < 8; z++) {
  63. buffSetPixel(buff, x, y, z);
  64. }
  65. }
  66. setImage(buff);
  67. while(!isFinished()) {
  68. wdt_reset();
  69. }
  70. buffClearAllPixels(buff);
  71. }
  72. //x-axis wave
  73. for(x = 0; x < 8; x++) {
  74. for(y = 0; y < 8; y++) {
  75. for(z = 0; z < 8; z++) {
  76. buffSetPixel(buff, x, y, z);
  77. }
  78. }
  79. setImage(buff);
  80. while(!isFinished()) {
  81. wdt_reset();
  82. }
  83. buffClearAllPixels(buff);
  84. }
  85. for(x = 7; x >= 0; x--) {
  86. for(y = 0; y < 8; y++) {
  87. for(z = 0; z < 8; z++) {
  88. buffSetPixel(buff, x, y, z);
  89. }
  90. }
  91. setImage(buff);
  92. while(!isFinished()) {
  93. wdt_reset();
  94. }
  95. buffClearAllPixels(buff);
  96. }
  97. //z-axis-wave
  98. for(z = 0; z < 8; z++) {
  99. for(y = 0; y < 8; y++) {
  100. for(x = 0; x < 8; x++) {
  101. buffSetPixel(buff, x, y, z);
  102. }
  103. }
  104. setImage(buff);
  105. while(!isFinished()) {
  106. wdt_reset();
  107. }
  108. buffClearAllPixels(buff);
  109. }
  110. for(z = 7; z >= 0; z--) {
  111. for(x = 0; x < 8; x++) {
  112. for(y = 0; y < 8; y++) {
  113. buffSetPixel(buff, x, y, z);
  114. }
  115. }
  116. setImage(buff);
  117. while(!isFinished()) {
  118. wdt_reset();
  119. }
  120. buffClearAllPixels(buff);
  121. }
  122. }
  123. void anotherAnimation(void) {
  124. }