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 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. }