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.

lookUp.c 765B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <stdio.h>
  2. int flip(int d) {
  3. int n;
  4. int converted = 0;
  5. for (n = 0; n < 8; n++) {
  6. if (d & (1 << (7 - n))) {
  7. converted |= (1 << n);
  8. }
  9. }
  10. return converted;
  11. }
  12. int flipAdjacent(int d) {
  13. int n;
  14. int converted = 0;
  15. for (n = 0; n < 7; n+= 2) {
  16. if (d & (1 << n)) {
  17. converted |= (1 << (n + 1));
  18. } else {
  19. converted &= ~(1 << (n + 1));
  20. }
  21. if (d & (1 << (n + 1))) {
  22. converted |= (1 << n);
  23. } else {
  24. converted &= ~(1 << n);
  25. }
  26. }
  27. return converted;
  28. }
  29. int main() {
  30. int byte;
  31. printf("uint8_t lookUp[256] = {");
  32. for (byte = 0; byte < 256; byte++) {
  33. printf(" %d", flipAdjacent(flip(byte));
  34. if (((byte % 10) == 0) && (byte > 0)) {
  35. printf(",\n");
  36. } else if (byte < 255) {
  37. printf(", ");
  38. }
  39. }
  40. printf(" }\n");
  41. return 0;
  42. }