8x8x8 Led Cube driven by 4x PCF8575 for the columns and 1x PCF8574 for the layers

Revision:
0:920c5ed65a45
Child:
1:e08a4d27f534
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/led_cube.cpp	Sat Sep 08 22:14:10 2012 +0000
@@ -0,0 +1,73 @@
+#include "led_cube.h"
+
+LED_CUBE::LED_CUBE(I2C* _interface)
+    : row(_interface, 0x07,PCF8574_TYPE),
+      colums_0_1(_interface, 0x00),
+      colums_2_3(_interface, 0x01),
+      colums_4_5(_interface, 0x02),
+      colums_6_7(_interface, 0x03)
+{
+    _interface->frequency(400000); //400KHz
+    duty.attach_us(this, &LED_CUBE::UpdateRow,1250);// each row = 1/8 duty
+}
+
+LED_CUBE::~LED_CUBE() {}
+
+void LED_CUBE::UpdateRow()
+{
+    static int rownr = 0;
+
+    if (rownr < 0 || rownr > 7) {
+        rownr = 0;
+    }
+    row.WriteByte(0xFF); // switch off all rows before updating next colums to avoid ghost data from previous colums
+    colums_0_1.WriteBytes(~cubeData[8 * rownr + 0],~cubeData[8 * rownr + 2]); //update the columns
+    colums_2_3.WriteBytes(~cubeData[8 * rownr + 1],~cubeData[8 * rownr + 3]);
+    colums_4_5.WriteBytes(~cubeData[8 * rownr + 6],~cubeData[8 * rownr + 4]);
+    colums_6_7.WriteBytes(~cubeData[8 * rownr + 7],~cubeData[8 * rownr + 5]);
+    row.WriteByte(~(1<<rownr)); // now display the row
+    rownr++;
+}
+
+//clear everything
+void LED_CUBE::clear_cube(void){
+    row.WriteByte(0xFF);
+    colums_0_1.WriteBytes(0xFF,0xFF);
+    colums_2_3.WriteBytes(0xFF,0xFF);
+    colums_4_5.WriteBytes(0xFF,0xFF);
+    colums_6_7.WriteBytes(0xFF,0xFF);
+    clearVoxels();
+}
+
+//set a voxel in my space saver cube array
+void LED_CUBE::setVoxel(unsigned char x, unsigned char y, unsigned char z){
+    cubeData[z*8 + y] |= 0x01<<x;
+}
+
+//clear a single voxel in my space saver cube array
+void LED_CUBE::clearVoxel(unsigned char x, unsigned char y, unsigned char z){
+    cubeData[z*8 + y] &= ~(0x01<<x);
+}
+
+//return the value of the voxel in my cube array
+unsigned char LED_CUBE::getVoxel(unsigned char x, unsigned char y, unsigned char z){
+    if(cubeData[z*8 + y] & 0x01<<x){
+        return 1;
+    }else{
+        return 0;
+    }
+}
+
+void LED_CUBE::copyColumn(unsigned char x, unsigned char y, unsigned char col){
+    for(unsigned char z = 0; z < Zd; z++){
+        if(col&(0x01<<z)){
+            setVoxel(x, y, z);
+        }else{
+            clearVoxel(x, y, z);
+        }
+    }
+}
+//clear all the voxels in the array
+void LED_CUBE::clearVoxels(void){
+    memset(cubeData, 0, 64*sizeof(unsigned char));
+}
\ No newline at end of file