Simple single-color 8x8x8 LED Cube with AVRs
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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