Simple single-color 8x8x8 LED Cube with AVRs
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AFrame.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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];
  35. private short duration = 1;
  36. private String name = "Frame";
  37. private static int lastIndex = 1;
  38. /**
  39. * Give it a nice name.
  40. */
  41. public AFrame() {
  42. name = "Frame " + lastIndex++;
  43. }
  44. /**
  45. * Gets the Name of this Frame
  46. *
  47. * @return Name of the Frame
  48. */
  49. public String getName() {
  50. return name;
  51. }
  52. /**
  53. * Sets the Name of this Frame
  54. *
  55. * @param s New Name
  56. */
  57. public void setName(String s) {
  58. name = s;
  59. }
  60. /**
  61. * Sets the Data of this Frame
  62. *
  63. * @param d 64 bytes that contain data (8 bit per byte, so 8 LEDs)
  64. */
  65. public void setData(short[] d) {
  66. for (int i = 0; i < 64; i++) {
  67. data[i] = d[i];
  68. }
  69. }
  70. /**
  71. * Gets tha Data of this Frame
  72. *
  73. * @return 64 bytes that contain data (8 bits / LEDs per byte)
  74. */
  75. public short[] getData() {
  76. return data;
  77. }
  78. /**
  79. * Sets the Duration of this Frame
  80. *
  81. * @param t Duration of frame in (( t * (1/24) ) + (1/24)) seconds
  82. */
  83. public void setTime(short t) {
  84. duration = t;
  85. }
  86. /**
  87. * Gets the Duration of this Frame.
  88. * 0 means (1/24) seconds.
  89. *
  90. * @return Duration of frame.
  91. * @see AFrame#setTime(short) setTime()
  92. */
  93. public short getTime() {
  94. return duration;
  95. }
  96. /**
  97. * Gets the Data of the Layer you want
  98. *
  99. * @param i Number of Layer you want
  100. * @return 8 byte array with data of selected layer
  101. */
  102. public short[] getLayer(int i) {
  103. return Arrays.copyOfRange(data, (i * 8), (i * 8) + 8);
  104. }
  105. }