Simple single-color 8x8x8 LED Cube with AVRs
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

lookUp.c 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * lookUp.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. // Small utility to create a look up table for CubeFirmware.
  22. // This is needed for our second cube, because we mirrored the connection cable.
  23. #include <stdio.h>
  24. int flip(int d) {
  25. int n;
  26. int converted = 0;
  27. for (n = 0; n < 8; n++) {
  28. if (d & (1 << (7 - n))) {
  29. converted |= (1 << n);
  30. }
  31. }
  32. return converted;
  33. }
  34. int flipAdjacent(int d) {
  35. int n;
  36. int converted = 0;
  37. for (n = 0; n < 7; n+= 2) {
  38. if (d & (1 << n)) {
  39. converted |= (1 << (n + 1));
  40. } else {
  41. converted &= ~(1 << (n + 1));
  42. }
  43. if (d & (1 << (n + 1))) {
  44. converted |= (1 << n);
  45. } else {
  46. converted &= ~(1 << n);
  47. }
  48. }
  49. return converted;
  50. }
  51. int main() {
  52. int byte;
  53. printf("uint8_t lookUp[256] = {");
  54. for (byte = 0; byte < 256; byte++) {
  55. printf(" %d", flipAdjacent(flip(byte));
  56. if (((byte % 10) == 0) && (byte > 0)) {
  57. printf(",\n");
  58. } else if (byte < 255) {
  59. printf(", ");
  60. }
  61. }
  62. printf(" }\n");
  63. return 0;
  64. }