Pixie Chroma
Documentation for the easiest 5x7 LED displays for Arduino!
pixie_chroma_internal.h
Go to the documentation of this file.
1 
10 #ifndef pixie_chroma_h
11 #define pixie_chroma_h
12 
13 #include "Arduino.h"
14 
18  MANUAL
19 };
20 //............................................................................
27  public:
29  PixieChroma();
30 
31  /*+-- Functions - Setup ------------------------------------------------------------*/
32  /*|*/ void begin( const uint8_t data_pin, uint8_t pixies_x, uint8_t pixies_y );
33  /*|*/ void begin_quad( uint8_t pixies_per_pin, uint8_t pixies_x, uint8_t pixies_y );
34  /*|*/ void set_brightness( uint8_t level );
35  /*|*/ void set_palette( const uint8_t* pal );
36  /*|*/ void set_palette( CRGBPalette16 pal );
37  /*|*/ void set_animation( void ( *action )( PixieChroma*, float ) );
38  /*|*/ void set_animation_speed( float speed );
39  /*|*/ void set_gamma_correction( bool enabled );
40  /*|*/ void set_max_power( float volts, uint16_t milliamps );
41  /*|*/ void set_frame_rate_target( uint16_t target );
42  /*|*/ void set_line_wrap( bool enabled );
43  /*|*/ void set_update_mode( t_update_mode mode, uint16_t FPS = 60 );
44  /*+---------------------------------------------------------------------------------*/
45 
46  /*+-- Functions - write( ) ----------------------------------------------------------*/
47  /*|*/ void write( const uint8_t* icon, uint8_t x_pos = 0, uint8_t y_pos = 0 );
48  /*|*/ void write( uint8_t icon_col_1, uint8_t icon_col_2, uint8_t icon_col_3, uint8_t icon_col_4, uint8_t icon_col_5, uint8_t x_pos = 0, uint8_t y_pos = 0 );
49  /*|*/ void write( char* message, uint8_t x_pos = 0, uint8_t y_pos = 0 );
50  /*|*/ void write( int16_t input, uint8_t x_pos = 0, uint8_t y_pos = 0 );
51  /*|*/ void write( uint16_t input, uint8_t x_pos = 0, uint8_t y_pos = 0 );
52  /*|*/ void write( int32_t input, uint8_t x_pos = 0, uint8_t y_pos = 0 );
53  /*|*/ void write( uint32_t input, uint8_t x_pos = 0, uint8_t y_pos = 0 );
54  /*|*/ void write( long unsigned int input, uint8_t x_pos = 0, uint8_t y_pos = 0 ); // pretty much the same as uint32_t, but Arduino is stupid
55  /*|*/ void write( float input, uint8_t places = 2, uint8_t x_pos = 0, uint8_t y_pos = 0 );
56  /*|*/ void write( double input, uint8_t places = 2, uint8_t x_pos = 0, uint8_t y_pos = 0 );
57  /*|*/
58  /*|*/ void write_pix( char* message, int16_t x_offset = 0, int16_t y_offset = 0 );
59  /*|*/ void write_pix( const uint8_t* icon, int16_t x_offset = 0, int16_t y_offset = 0 );
60  /*|*/
61  /*|*/ void add_char( char c, int16_t x_pos, int16_t y_pos );
62  /*|*/ void add_char( const uint8_t* icon, int16_t x_pos, int16_t y_pos );
63  /*+---------------------------------------------------------------------------------*/
64 
65  /*+-- Functions - print( ) ----------------------------------------------------------*/
66  /*|*/ void print( const uint8_t* icon );
67  /*|*/ void print( uint8_t icon_col_1, uint8_t icon_col_2, uint8_t icon_col_3, uint8_t icon_col_4, uint8_t icon_col_5 );
68  /*|*/ void print( char* message );
69  /*|*/ void print( int16_t input );
70  /*|*/ void print( uint16_t input );
71  /*|*/ void print( int32_t input );
72  /*|*/ void print( uint32_t input );
73  /*|*/ void print( long unsigned int input ); // pretty much the same as uint32_t, but Arduino is stupid
74  /*|*/ void print( float input, uint8_t places = 2 );
75  /*|*/ void print( double input, uint8_t places = 2 );
76  /*+---------------------------------------------------------------------------------*/
77 
78  /*+-- Functions - println( ) --------------------------------------------------------*/
79  /*|*/ void println( const uint8_t* icon );
80  /*|*/ void println( uint8_t icon_col_1, uint8_t icon_col_2, uint8_t icon_col_3, uint8_t icon_col_4, uint8_t icon_col_5 );
81  /*|*/ void println( char* message );
82  /*|*/ void println( int16_t input );
83  /*|*/ void println( uint16_t input );
84  /*|*/ void println( int32_t input );
85  /*|*/ void println( uint32_t input );
86  /*|*/ void println( long unsigned int input ); // pretty much the same as uint32_t, but Arduino is stupid
87  /*|*/ void println( float input, uint8_t places = 2 );
88  /*|*/ void println( double input, uint8_t places = 2 );
89  /*+---------------------------------------------------------------------------------*/
90 
91  /*+-- Functions - Cursor -----------------------------------------------------------*/
92  /*|*/ void set_cursor( uint8_t x_position, uint8_t y_position = 0 );
93  /*|*/ uint8_t get_cursor_x();
94  /*|*/ uint8_t get_cursor_y();
95  /*|*/ int16_t get_cursor_x_exact();
96  /*|*/ int16_t get_cursor_y_exact();
97  /*+---------------------------------------------------------------------------------*/
98 
99  /*+-- Functions - Updating the mask/LEDS -------------------------------------------*/
100  /*|*/ void clear();
101  /*|*/ void show();
102  /*|*/ void hold();
103  /*|*/ void free();
104  /*+---------------------------------------------------------------------------------*/
105 
106  /*+-- Functions - Color ------------------------------------------------------------*/
107  /*|*/ void color( CRGB col ); // Set all displays
108  /*|*/ void color( CRGB col, uint8_t x, uint8_t y ); // Set one display
109  /*|*/ void color( CRGB col, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2 ); // Set a 2D rectangle
110  /*|*/ CRGB kelvin_to_rgb( uint16_t temperature ); // Get an approximate CRGB ( not yet gamma corrected ) of a blackbody radiation temperature
111  /*+---------------------------------------------------------------------------------*/
112 
113  /*+-- Functions - Mask Effects -----------------------------------------------------*/
114  /*|*/ void dim( uint8_t amount, bool reset_cursor = false ); // Fade towards black by amount
115  /*|*/ void blur( fract8 blur_amount );
116  /*|*/ void blur_x( fract8 blur_amount );
117  /*|*/ void blur_y( fract8 blur_amount );
118  /*+---------------------------------------------------------------------------------*/
119 
120  /*+-- Functions - Color Effects ----------------------------------------------------*/
121  /*|*/ void color_dim( uint8_t amount ); // Fade towards black by amount
122  /*|*/ void color_blur( fract8 blur_amount );
123  /*|*/ void color_blur_x( fract8 blur_amount );
124  /*|*/ void color_blur_y( fract8 blur_amount );
125  /*+---------------------------------------------------------------------------------*/
126 
127  /*+-- Functions - 2D Tools ---------------------------------------------------------*/
128  /*|*/ uint16_t xy( int32_t x, int32_t y, bool wrap = false );
129  /*|*/ uint16_t uv( float x, float y, bool wrap = false );
130  /*|*/ float get_uv_x( int32_t x_pixel );
131  /*|*/ float get_uv_y( int32_t y_pixel );
132  /*|*/ void draw_line( int16_t x1, int16_t y1, int16_t x2, int16_t y2 );
133  /*|*/ void print_xy_table();
134  /*+---------------------------------------------------------------------------------*/
135 
136  // Variables -------------------------------------------------------------------------
137 //............................................................................
163  CRGB *color_map;
164  //............................................................................
182  uint8_t *mask;
183  //............................................................................
188  CRGBPalette16 current_palette;
189  //............................................................................
194  uint16_t matrix_width;
195  //............................................................................
200  uint16_t matrix_height;
201 //............................................................................
208  uint16_t NUM_PIXELS;
209  //............................................................................
215  uint16_t NUM_LEDS;
216  //............................................................................
222  float delta = 1.0;
223  //............................................................................
228  float animation_speed = 1.0;
229  //............................................................................
234  float frame_rate;
235 
236  private:
237  // Functions ----------------------------------
238  void build_controller( const uint8_t pin );
239  void calc_xy();
240 
241  // Variables ----------------------------------
242  Ticker animate;
243 
244  const uint8_t display_width = 7;
245  const uint8_t display_height = 11;
246  const uint8_t display_padding_x = 1;
247  const uint8_t display_padding_y = 2;
248  const uint8_t leds_per_pixie = 70;
249  const uint8_t bit_table[2] = {0,255};
250 
251  volatile int16_t cursor_x;
252  volatile int16_t cursor_y;
253  volatile int16_t cursor_x_temp;
254  volatile int16_t cursor_y_temp;
255 
256  CRGB *color_map_out;
257  uint8_t *mask_out;
258  int16_t *xy_table;
259  uint32_t t_last;
260 
261  float max_V = 5;
262  uint16_t max_mA = 500;
263  uint8_t brightness_level = 255;
264 
265  bool correct_gamma = false;
266  bool line_wrap = true;
267 
268  bool freeze = false;
269  bool ticker_running = false;
270  float fps_target = 60;
271 
272  uint8_t pixie_pin;
273  uint8_t chars_x;
274  uint8_t chars_y;
275 };
276 
277 #endif
This is the software documentation for using Pixie Chroma functions on Arduino! For full example usag...
uint16_t NUM_PIXELS
Stores the total number of pixels, including invisible pixels.
void color_blur(fract8 blur_amount)
Blurs the color buffer in both axes by blur_amount.
void draw_line(int16_t x1, int16_t y1, int16_t x2, int16_t y2)
Draws a line in the mask buffer using Bresenham's line algorithm.
void color(CRGB col)
Sets the entire color buffer to a CRGB value.
void println(const uint8_t *icon)
Prints an Icon to the displays at the current cursor position, then jumps to the next row in the Pixi...
float animation_speed
Used by animation functions to scale the apparent speed of animation.
void write_pix(char *message, int16_t x_offset=0, int16_t y_offset=0)
Internal function for rendering char* strings to the mask buffer.
void set_brightness(uint8_t level)
Takes an 8-bit brightness value and passes it to FastLED internally, to provide global brightness con...
PixieChroma()
Construct a Pixie Chroma class object.
float delta
Used by animation functions as a way of self-regulating speed if performance drops,...
float get_uv_y(int32_t y_pixel)
Returns the Y-axis UV coordinate for a given Y-axis pixel position.
CRGB * color_map
Contains the entire color map, including "invisible" areas.
void set_line_wrap(bool enabled)
Sets the line wrapping behavior.
void add_char(char c, int16_t x_pos, int16_t y_pos)
Internal function for rendering a single char to the mask buffer.
void print_xy_table()
Prints the index table for the calculated XY map. Requires Serial.begin() first to function.
uint8_t * mask
Contains the entire mask, including "invisible" areas.
void begin(const uint8_t data_pin, uint8_t pixies_x, uint8_t pixies_y)
Initializes the display buffer, populates the XY coordinate table, defaults the display colors to gre...
void print(const uint8_t *icon)
Prints an Icon to the displays, at the current cursor position.
void free()
Unfreezes the current mask buffer in memory to allow showing updated text the next time show() is cal...
void blur(fract8 blur_amount)
Blurs the mask buffer in both axes by blur_amount.
void set_animation(void(*action)(PixieChroma *, float))
Accepts a preset or custom function to use for the animation ISR.
void clear()
Clears (blackens) the current mask buffer and resets the cursor to 0,0.
uint16_t NUM_LEDS
Stores the total number of physical LEDs, not including invisible pixels. This is calculated for you ...
uint16_t matrix_width
Stores the final width of the matrix, including invisible pixels.
CRGBPalette16 current_palette
The current FastLED CRGBPalette16 used for animations.
void show()
Processes 1D image data into truncated versions, sending them to the Pixie Chroma displays.
uint16_t uv(float x, float y, bool wrap=false)
This wrapper function returns the 1D color_map / mask index of a given OpenGL-style UV coordinate in ...
uint8_t get_cursor_y()
Returns the cursor's Y position.
void blur_x(fract8 blur_amount)
Blurs the mask buffer in the X axis by blur_amount.
void write(const uint8_t *icon, uint8_t x_pos=0, uint8_t y_pos=0)
Writes an icon* to a specified X and Y cursor position.
int16_t get_cursor_x_exact()
Returns the cursor's X position in exact pixel coordinates.
uint16_t xy(int32_t x, int32_t y, bool wrap=false)
This function returns the 1D color_map / mask index of a given 2D coordinate in the display matrix.
float get_uv_x(int32_t x_pixel)
Returns the X-axis UV coordinate for a given X-axis pixel position.
void color_blur_y(fract8 blur_amount)
Blurs the color buffer in the Y axis by blur_amount.
void color_blur_x(fract8 blur_amount)
Blurs the color buffer in the X axis by blur_amount.
void set_animation_speed(float speed)
Used to scale the animation speed of animation ISRs that can use pix.animation_speed() to scale their...
void color_dim(uint8_t amount)
Darkens the color buffer by an 8-bit amount.
void set_max_power(float volts, uint16_t milliamps)
Sets the maximum power budget in volts and milliamps.
uint16_t matrix_height
Stores the final height of the matrix, including invisible pixels.
int16_t get_cursor_y_exact()
Returns the cursor's Y position in exact pixel coordinates.
float frame_rate
Allows the user to access a live frame rate calculation (1 frame latency)
void set_frame_rate_target(uint16_t target)
Sets the target frame rate for animation. This target frame rate is only used to calculate delta in c...
void set_palette(const uint8_t *pal)
Accepts a const uint8_t (8-bit) array to generate a FastLED Gradient Palette at runtime:
void dim(uint8_t amount, bool reset_cursor=false)
Darkens the mask buffer by an 8-bit amount. Optionally resets the cursor position.
void set_update_mode(t_update_mode mode, uint16_t FPS=60)
Allows for automatic show() calls at a specified frames per second if AUTOMATIC is used....
void set_cursor(uint8_t x_position, uint8_t y_position=0)
Sets the cursor position in a 2D context, in whole displays.
void set_gamma_correction(bool enabled)
Allows you to enable built-in automatic gamma correction, using a fast LUT in pixie_utility....
CRGB kelvin_to_rgb(uint16_t temperature)
Approximates the conversion of a blackbody radiation temperature (i.e. 3500K) to a CRGB color object.
void begin_quad(uint8_t pixies_per_pin, uint8_t pixies_x, uint8_t pixies_y)
Initializes the display buffer, populates the XY coordinate table, defaults the display colors to gre...
uint8_t get_cursor_x()
Returns the cursor's X position.
void blur_y(fract8 blur_amount)
Blurs the mask buffer in the Y axis by blur_amount.
void hold()
Freezes the current mask buffer in memory to prevent showing unfinished text if show() automaticall f...