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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. for(y = 0; y < 8; y++) {
  47. for(x = 0; x < 8; x++) {
  48. for(z = 0; z < 8; z++) {
  49. buffSetPixel(buff, x, y, z);
  50. }
  51. }
  52. setImage(buff);
  53. while(!isFinished()) {
  54. wdt_reset();
  55. }
  56. for(x = 0; x < 8; x++) {
  57. for(z = 0; z < 8; z++) {
  58. buffClearPixel(buff, x, y, z);
  59. }
  60. }
  61. }
  62. // Down-wave (Frames 9-15 of showoff.cube)
  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. for(x = 0; x < 8; x++) {
  74. for(z = 0; z < 8; z++) {
  75. buffClearPixel(buff, x, y, z);
  76. }
  77. }
  78. }
  79. }
  80. void anotherAnimation(void) {
  81. }