8x8x8 Led Cube driven by 4x PCF8575 for the columns and 1x PCF8574 for the layers
Diff: led_cube.h
- Revision:
- 1:e08a4d27f534
- Parent:
- 0:920c5ed65a45
diff -r 920c5ed65a45 -r e08a4d27f534 led_cube.h --- a/led_cube.h Sat Sep 08 22:14:10 2012 +0000 +++ b/led_cube.h Thu Nov 01 22:31:54 2012 +0000 @@ -1,46 +1,66 @@ -#ifndef __LED_CUBE_H -#define __LED_CUBE_H - -#define VERSION 1.0 - -#include <mbed.h> -#include "pcf8574.h" -#include "pcf8575.h" - -#define PI 3.14159 -#define Xd 8 -#define Yd 8 -#define Zd 8 -#define centre 3.5 -#define Vd Xd*Yd*Zd - -#define SB(x,n) (x|=(1<<n)) -#define CB(x,n) (x&=~(1<<n)) -#define TB(x,n) (x^=(1<<n)) -#define PB(x,n) do{SB(x,n);CB(x,n);}while(0) - -class LED_CUBE -{ -public: - LED_CUBE(I2C* _interface); - ~LED_CUBE(void); - - void clear_cube(void); - void setVoxel(unsigned char x, unsigned char y, unsigned char z); - void clearVoxel(unsigned char x, unsigned char y, unsigned char z); - unsigned char getVoxel(unsigned char x, unsigned char y, unsigned char z); - void copyColumn(unsigned char x, unsigned char y, unsigned char col); - void clearVoxels(void); - -private: - PCF8574 row; - PCF8575 colums_0_1; - PCF8575 colums_2_3; - PCF8575 colums_4_5; - PCF8575 colums_6_7; - unsigned char cubeData[64]; - Ticker duty; - void UpdateRow(void); - -}; +#ifndef __LED_CUBE_H +#define __LED_CUBE_H + +#define VERSION 1.0 + +#include <mbed.h> +#include "pcf8574.h" +#include "pcf8575.h" + +#define AXIS_X 1 +#define AXIS_Y 2 +#define AXIS_Z 3 +#define PI 3.14159265 +#define center 3.5 +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) + +class LED_CUBE +{ +public: + LED_CUBE(I2C* _interface); + ~LED_CUBE(void); + + void clear_cube(void); + void setVoxel(unsigned char x, unsigned char y, unsigned char z); + void clearVoxel(unsigned char x, unsigned char y, unsigned char z); + unsigned char getVoxel(unsigned char x, unsigned char y, unsigned char z); + void copyColumn(unsigned char x, unsigned char y, unsigned char col); + void alterVoxel(unsigned char x, unsigned char y, unsigned char z, unsigned char state); + void flipVoxel(unsigned char x, unsigned char y, unsigned char z); + void setPlane_x (int x); + void clearPlane_x (int x); + void setPlane_y (int y); + void clearPlane_y (int y); + void setPlane_z (int z); + void clearPlane_z (int z); + void setPlane (char axis, unsigned char i); + void clearPlane (char axis, unsigned char i); + void setSlope_XY(int x1, int y1, int x2, int y2); + void setSlope_XZ(int x1, int z1, int x2, int z2); + void setSlope_YZ(int y1, int z1, int y2, int z2); + void clearVoxels(void); + void fill (unsigned char pattern); + void box_filled(int x1, int y1, int z1, int x2, int y2, int z2); + void box_walls(int x1, int y1, int z1, int x2, int y2, int z2); + void box_wireframe(int x1, int y1, int z1, int x2, int y2, int z2); + void line(int x1, int y1, int z1, int x2, int y2, int z2); + void circle(int xr, int yr, int zr, int d ,char axis); + void CopyBlock(int x1, int y1, int z1, int x2, int y2, int z2, int xc, int yc, int zc); + void MoveBlock(int x1, int y1, int z1, int x2, int y2, int z2, int xm, int ym, int zm); + void RotateBlock(int x1, int y1, int height, char axis, char dir); + +private: + PCF8574 row; + PCF8575 colums_0_1; + PCF8575 colums_2_3; + PCF8575 colums_4_5; + PCF8575 colums_6_7; + unsigned char cubeData[64]; + Ticker duty; + void UpdateRow(void); + char byteline (int start, int end); + unsigned char inrange(int x, int y, int z); + void argorder(int ix1, int ix2, int *ox1, int *ox2); + double map(double in, double inMin, double inMax, double outMin, double outMax); + }; #endif \ No newline at end of file