L3D Cube Library
 All Classes Functions Pages
L3D.h
1 #ifndef _L3D_H
2 #define _L3D_H
3 
4 #include "application.h"
5 #include "neopixel.h"
6 
7 #define PIXEL_COUNT 512
8 #define PIXEL_PIN D0
9 #define PIXEL_TYPE WS2812B
10 
11 #define INTERNET_BUTTON D2
12 #define MODE D3
13 
14 #define STREAMING_PORT 2222
15 
17 struct Color
18 {
19  unsigned char red, green, blue;
20 
21  Color(int r, int g, int b) : red(r), green(g), blue(b) {}
22  Color() : red(0), green(0), blue(0) {}
23 };
24 
26 struct Point
27 {
28  float x;
29  float y;
30  float z;
31  Point() : x(0), y(0), z(0) {}
32  Point(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}
33 };
34 
38 class Cube
39 {
40  private:
41  bool onlinePressed;
42  bool lastOnline;
43  Adafruit_NeoPixel strip;
44  UDP udp;
45  int lastUpdated;
46  char localIP[24];
47  char macAddress[20];
48  int port;
49  void emptyFlatCircle(int x, int y, int z, int r, Color col);
50 
51  public:
52  int size;
53  int maxBrightness;
54 
55  Cube(unsigned int s, unsigned int mb);
56  Cube(void);
57 
58  void setVoxel(int x, int y, int z, Color col);
59  void setVoxel(Point p, Color col);
60  Color getVoxel(int x, int y, int z);
61  Color getVoxel(Point p);
62  void line(int x1, int y1, int z1, int x2, int y2, int z2, Color col);
63  void line(Point p1, Point p2, Color col);
64  void sphere(int x, int y, int z, int r, Color col);
65  void sphere(Point p, int r, Color col);
66  void shell(float x, float y, float z, float r, Color col);
67  void shell(float x, float y, float z, float r, float thickness, Color col);
68  void shell(Point p, float r, Color col);
69  void shell(Point p, float r, float thickness, Color col);
70  void background(Color col);
71 
72  Color colorMap(float val, float min, float max);
73  Color lerpColor(Color a, Color b, int val, int min, int max);
74 
75  void begin(void);
76  void show(void);
77  void listen(void);
78  void initCloudButton(void);
79  void checkCloudButton(void);
80  void updateNetworkInfo(void);
81  int setPort(String port);
82 };
83 
84 // common colors
85 const Color black = Color(0x00, 0x00, 0x00);
86 const Color grey = Color(0x92, 0x95, 0x91);
87 const Color yellow = Color(0xff, 0xff, 0x14);
88 const Color magenta = Color(0xc2, 0x00, 0x78);
89 const Color orange = Color(0xf9, 0x73, 0x06);
90 const Color teal = Color(0x02, 0x93, 0x86);
91 const Color red = Color(0xe5, 0x00, 0x00);
92 const Color brown = Color(0x65, 0x37, 0x00);
93 const Color pink = Color(0xff, 0x81, 0xc0);
94 const Color blue = Color(0x03, 0x43, 0xdf);
95 const Color green = Color(0x15, 0xb0, 0x1a);
96 const Color purple = Color(0x7e, 0x1e, 0x9c);
97 const Color white = Color(0xff, 0xff, 0xff);
98 
99 #endif
void updateNetworkInfo(void)
Update the cube's knowledge of its own network address.
Definition: L3D.cpp:487
void show(void)
Make changes to the cube visible.
Definition: L3D.cpp:406
int setPort(String port)
Function to be called via Spark API for updating the streaming port number.
Definition: L3D.cpp:500
void background(Color col)
Set the entire cube to one color.
Definition: L3D.cpp:322
void sphere(int x, int y, int z, int r, Color col)
Draw a filled sphere.
Definition: L3D.cpp:201
Color colorMap(float val, float min, float max)
Map a value into a color.
Definition: L3D.cpp:339
An RGB color.
Definition: L3D.h:17
Color lerpColor(Color a, Color b, int val, int min, int max)
Linear interpolation between colors.
Definition: L3D.cpp:394
void begin(void)
Initialization of cube resources and environment.
Definition: L3D.cpp:31
void listen(void)
Listen for the start of UDP streaming.
Definition: L3D.cpp:456
Color getVoxel(int x, int y, int z)
Get the color of a voxel at a position.
Definition: L3D.cpp:74
An L3D LED cube.
Definition: L3D.h:38
void shell(float x, float y, float z, float r, Color col)
Draw a shell (empty sphere).
Definition: L3D.cpp:233
Definition: neopixel.h:51
void setVoxel(int x, int y, int z, Color col)
Set a voxel at a position to a color.
Definition: L3D.cpp:51
void initCloudButton(void)
Initialize cloud switch hardware.
Definition: L3D.cpp:412
void line(int x1, int y1, int z1, int x2, int y2, int z2, Color col)
Draw a line in 3D space.
Definition: L3D.cpp:98
Cube(void)
Construct a new cube with default settings.
Definition: L3D.cpp:23
A point in 3D space.
Definition: L3D.h:26
void checkCloudButton(void)
Check cloud switch hardware.
Definition: L3D.cpp:431