Simple single-color 8x8x8 LED Cube with AVRs
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

generator.c 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * generator.c
  3. *
  4. * Copyright 2012 Thomas Buck <xythobuz@me.com>
  5. *
  6. * This file is part of LED-Cube.
  7. *
  8. * LED-Cube is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * LED-Cube is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <avr/io.h>
  22. #include <util/delay.h>
  23. #include <stdint.h>
  24. #include <stdlib.h>
  25. #include "memLayer.h"
  26. #include "font.h"
  27. #include "buffhelp.h"
  28. // Generate 8 frames, store them from index start.
  29. // data has 8 bytes --> 1 layer. This layer is moved from back to front.
  30. void generateMovingAnimation(uint8_t *data, uint16_t start, uint8_t duration) {
  31. uint8_t i, j, d;
  32. uint8_t *frame = (uint8_t *)malloc(65);
  33. frame[64] = duration;
  34. for (i = 0; i < 8; i++) {
  35. d = 0;
  36. for (j = 0; j < 64; j++) {
  37. if ((j < (8 * (i + 1))) && (j >= (8 * i))) {
  38. frame[j] = data[d++];
  39. } else {
  40. frame[j] = 0;
  41. }
  42. }
  43. setFrame(i + start, frame);
  44. }
  45. free(frame);
  46. }
  47. void renderText(char *text, uint16_t start) {
  48. uint8_t *buf;
  49. while(text[0] != '\0') {
  50. generateMovingAnimation(getFont(text[0]), start, 1);
  51. start += 8;
  52. text++;
  53. }
  54. buf = buffNew();
  55. buf[64] = 12; // half second empty frame at end of text
  56. setFrame(start, buf);
  57. free(buf);
  58. }