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.

AFrame.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * AFrame.java
  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. import java.util.Arrays;
  24. /**
  25. * The representation of a single frame. Contains the data of all 512 LEDs in a
  26. * given time.
  27. *
  28. * @author Thomas Buck
  29. * @author Max Nuding
  30. * @author Felix Bäder
  31. * @version 1.0
  32. */
  33. public class AFrame {
  34. private short[] data = new short[64]; // data[y + (8 * z)] & (1 << x)
  35. private short duration = 1;
  36. private String name = "Frame";
  37. private static int lastIndex = 1;
  38. /**
  39. * Toggle a LED in this frame
  40. * @param x X Coordinate (0 - 7)
  41. * @param y Y Coord. (0 - 7)
  42. * @param z Z Coord. (0 - 7)
  43. */
  44. public void toggleLED(int x, int y, int z) {
  45. if (x < 8) {
  46. if (y < 8) {
  47. if (z < 8) {
  48. data[y + (8 * z)] ^= (1 << x);
  49. }
  50. }
  51. }
  52. }
  53. /**
  54. * Give it a nice name.
  55. */
  56. public AFrame() {
  57. name = "Frame " + lastIndex++;
  58. }
  59. /**
  60. * Gets the Name of this Frame
  61. *
  62. * @return Name of the Frame
  63. */
  64. public String getName() {
  65. return name;
  66. }
  67. /**
  68. * Sets the Name of this Frame
  69. *
  70. * @param s New Name
  71. */
  72. public void setName(String s) {
  73. name = s;
  74. }
  75. /**
  76. * Sets the Data of this Frame
  77. *
  78. * @param d 64 bytes that contain data (8 bit per byte, so 8 LEDs)
  79. */
  80. public void setData(short[] d) {
  81. for (int i = 0; i < 64; i++) {
  82. data[i] = d[i];
  83. }
  84. }
  85. /**
  86. * Gets tha Data of this Frame
  87. *
  88. * @return 64 bytes that contain data (8 bits / LEDs per byte)
  89. */
  90. public short[] getData() {
  91. return data;
  92. }
  93. /**
  94. * Sets the Duration of this Frame
  95. *
  96. * @param t Duration of frame in (( t * (1/24) ) + (1/24)) seconds
  97. */
  98. public void setTime(short t) {
  99. duration = t;
  100. }
  101. /**
  102. * Gets the Duration of this Frame.
  103. * 0 means (1/24) seconds.
  104. *
  105. * @return Duration of frame.
  106. * @see AFrame#setTime(short) setTime()
  107. */
  108. public short getTime() {
  109. return duration;
  110. }
  111. /**
  112. * Gets the Data of the Layer you want
  113. *
  114. * @param i Number of Layer you want
  115. * @return 8 byte array with data of selected layer
  116. */
  117. public short[] getLayer(int i) {
  118. return Arrays.copyOfRange(data, (i * 8), (i * 8) + 8);
  119. }
  120. }