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
15
19 MANUAL
20};
21
24 LEFT,
25 CENTER,
26 RIGHT
27};
28
31 SMOOTH,
32 SHIFT,
33 INSTANT
34};
35//............................................................................
43 public:
45 PixieChroma();
46
47 /*+-- Functions - Setup ------------------------------------------------------------*/
48 /*|*/ void begin( const uint8_t data_pin, uint8_t pixies_x, uint8_t pixies_y );
49 /*|*/ void begin_quad( uint8_t pixies_per_pin, uint8_t pixies_x, uint8_t pixies_y );
50 /*|*/ void set_color_animation( void ( *action )( PixieChroma*, float ) );
51 /*|*/ void set_color_animation_speed( float speed );
52 /*|*/ void set_brightness( uint8_t level );
53 /*|*/ void set_frame_rate_target( uint16_t target );
54 /*|*/ void set_gamma_correction( bool enabled );
55 /*|*/ void set_justification( t_justification justification, int16_t row = -1 );
56 /*|*/ void set_line_wrap( bool enabled );
57 /*|*/ void set_max_power( float volts, uint16_t milliamps );
58 /*|*/ void set_palette( const uint8_t* pal );
59 /*|*/ void set_palette( CRGBPalette16 pal );
60 /*|*/ void set_scroll_type(t_scroll_type type);
61 /*|*/ void set_update_mode( t_update_mode mode, uint16_t FPS = 60 );
62 /*+---------------------------------------------------------------------------------*/
63
64 /*+-- Functions - write( ) ----------------------------------------------------------*/
65 /*|*/ void add_char( char chr, int16_t x_pos, int16_t y_pos );
66 /*|*/ void add_char( uint8_t bitmap_col_1, uint8_t bitmap_col_2, uint8_t bitmap_col_3, uint8_t bitmap_col_4, uint8_t bitmap_col_5, int16_t x_pos, int16_t y_pos );
67 /*|*/ void write( uint8_t bitmap_col_1, uint8_t bitmap_col_2, uint8_t bitmap_col_3, uint8_t bitmap_col_4, uint8_t bitmap_col_5, uint8_t x_pos = 0, uint8_t y_pos = 0 );
68 /*|*/ void write( char* message, uint8_t x_pos = 0, uint8_t y_pos = 0 );
69 /*|*/ void write( int16_t input, uint8_t x_pos = 0, uint8_t y_pos = 0 );
70 /*|*/ void write( uint16_t input, uint8_t x_pos = 0, uint8_t y_pos = 0 );
71 /*|*/ void write( int32_t input, uint8_t x_pos = 0, uint8_t y_pos = 0 );
72 /*|*/ void write( uint32_t input, uint8_t x_pos = 0, uint8_t y_pos = 0 );
73 /*|*/ #ifndef ARDUINO_ARCH_TEENSY_3_X
74 /*|*/ 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
75 /*|*/ #endif
76 /*|*/ void write( float input, uint8_t places = 2, uint8_t x_pos = 0, uint8_t y_pos = 0 );
77 /*|*/ void write( double input, uint8_t places = 2, uint8_t x_pos = 0, uint8_t y_pos = 0 );
78 /*|*/
79 /*|*/ void write_pix( char* message, int16_t x_offset = 0, int16_t y_offset = 0 );
80 /*|*/ void write_pix( uint8_t bitmap_col_1, uint8_t bitmap_col_2, uint8_t bitmap_col_3, uint8_t bitmap_col_4, uint8_t bitmap_col_5, int16_t x_dest = 0, int16_t y_dest = 0 );
81 /*|*/
82 /*+---------------------------------------------------------------------------------*/
83
84 /*+-- Functions - print( ) ----------------------------------------------------------*/
85 /*|*/ void print( uint8_t bitmap_col_1, uint8_t bitmap_col_2, uint8_t bitmap_col_3, uint8_t bitmap_col_4, uint8_t bitmap_col_5 );
86 /*|*/ void print( char chr );
87 /*|*/ void print( char* message );
88 /*|*/ void print( int16_t input );
89 /*|*/ void print( uint16_t input );
90 /*|*/ void print( int32_t input );
91 /*|*/ void print( uint32_t input );
92 /*|*/ #ifndef ARDUINO_ARCH_TEENSY_3_X
93 /*|*/ void print( long unsigned int input ); // pretty much the same as uint32_t, but Arduino is stupid
94 /*|*/ #endif
95 /*|*/ void print( float input, uint8_t places = 2 );
96 /*|*/ void print( double input, uint8_t places = 2 );
97 /*+---------------------------------------------------------------------------------*/
98
99 /*+-- Functions - println( ) --------------------------------------------------------*/
100 /*|*/ void println( uint8_t bitmap_col_1, uint8_t bitmap_col_2, uint8_t bitmap_col_3, uint8_t bitmap_col_4, uint8_t bitmap_col_5 );
101 /*|*/ void println( char* message );
102 /*|*/ void println( int16_t input );
103 /*|*/ void println( uint16_t input );
104 /*|*/ void println( int32_t input );
105 /*|*/ void println( uint32_t input );
106 /*|*/ #ifndef ARDUINO_ARCH_TEENSY_3_X
107 /*|*/ void println( long unsigned int input ); // pretty much the same as uint32_t, but Arduino is stupid
108 /*|*/ #endif
109 /*|*/ void println( float input, uint8_t places = 2 );
110 /*|*/ void println( double input, uint8_t places = 2 );
111 /*+---------------------------------------------------------------------------------*/
112
113 /*+-- Functions - Cursor -----------------------------------------------------------*/
114 /*|*/ uint8_t get_cursor_x();
115 /*|*/ int16_t get_cursor_x_exact();
116 /*|*/ uint8_t get_cursor_y();
117 /*|*/ int16_t get_cursor_y_exact();
118 /*|*/ void set_cursor( uint8_t x_position, uint8_t y_position = 0 );
119 /*+---------------------------------------------------------------------------------*/
120
121 /*+-- Functions - Updating the mask/LEDs -------------------------------------------*/
122 /*|*/ void clear();
123 /*|*/ void free();
124 /*|*/ void hold();
125 /*|*/ void show();
126 /*|*/ void delay(uint32_t milliseconds);
127 /*+---------------------------------------------------------------------------------*/
128
129 /*+-- Functions - Color ------------------------------------------------------------*/
130 /*|*/ void color( CRGB col ); // Set all displays
131 /*|*/ void color( CRGB col, uint8_t x, uint8_t y ); // Set one display
132 /*|*/ void color( CRGB col, int16_t x1, int16_t y1, int16_t x2, int16_t y2 ); // Set a 2D rectangle
133 /*|*/ void print_color( CRGB col );
134 /*|*/ CRGB kelvin_to_rgb( uint16_t temperature ); // Get an approximate CRGB ( not yet gamma corrected ) of a blackbody radiation temperature
135 /*+---------------------------------------------------------------------------------*/
136
137 /*+-- Functions - Mask Effects -----------------------------------------------------*/
138 /*|*/ void blur( fract8 blur_amount );
139 /*|*/ void blur_x( fract8 blur_amount );
140 /*|*/ void blur_y( fract8 blur_amount );
141 /*|*/ void dim( uint8_t amount, bool reset_cursor = false ); // Fade towards black by amount
142 /*+---------------------------------------------------------------------------------*/
143
144 /*+-- Functions - Color Effects ----------------------------------------------------*/
145 /*|*/ void color_blur( fract8 blur_amount );
146 /*|*/ void color_blur_x( fract8 blur_amount );
147 /*|*/ void color_blur_y( fract8 blur_amount );
148 /*|*/ void color_dim( uint8_t amount ); // Fade towards black by amount
149 /*+---------------------------------------------------------------------------------*/
150
151 /*+-- Functions - 2D Tools ---------------------------------------------------------*/
152 /*|*/ void draw_line_color( int16_t x1, int16_t y1, int16_t x2, int16_t y2, CRGB color );
153 /*|*/ void draw_line_mask( int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t value = 255 );
154 /*|*/ float get_uv_x( int32_t x_pixel );
155 /*|*/ float get_uv_y( int32_t y_pixel );
156 /*|*/ uint8_t get_pixel_mask( int32_t x, int32_t y );
157 /*|*/ CRGB get_pixel_color( int32_t x, int32_t y );
158 /*|*/ void print_xy_table();
159 /*|*/ void scroll_message( char* message, uint8_t row = 0 );
160 /*|*/ void set_pixel_mask( int32_t x, int32_t y, uint8_t value );
161 /*|*/ void set_pixel_color( int32_t x, int32_t y, CRGB color );
162 /*|*/ void shift_mask_x( int16_t amount, int16_t row = -1 );
163 /*|*/ void shift_mask_y( int16_t amount );
164 /*|*/ void shift_color_map_x( int16_t amount, int16_t row = -1 );
165 /*|*/ void shift_color_map_y( int16_t amount );
166 /*|*/ uint16_t uv( float x, float y, bool wrap = false );
167 /*|*/ uint16_t xy( int32_t x, int32_t y, bool wrap = false );
168 /*+---------------------------------------------------------------------------------*/
169
170 /*+-- Functions - Developer --------------------------------------------------------*/
171 /*|*/ bool unit_tests();
172 /*+---------------------------------------------------------------------------------*/
173
174 // Variables -------------------------------------------------------------------------
175//............................................................................
202 //............................................................................
220 uint8_t *mask;
221 //............................................................................
226 CRGBPalette16 current_palette;
227 //............................................................................
232 uint16_t matrix_width;
233 //............................................................................
239//............................................................................
246 uint16_t pixel_count;
247 //............................................................................
253 uint16_t led_count;
254 //............................................................................
260 float delta = 1.0;
261 //............................................................................
266 float animation_speed = 1.0;
267 //............................................................................
273
274 private:
275 // Functions ----------------------------------
276 void build_controller( const uint8_t pin );
277 void calc_xy();
278 void fetch_shortcode( char* message, uint16_t code_start, uint16_t code_end, bool return_code = false );
279 void parse_custom_shortcode( char* message, uint16_t code_start, uint16_t code_end, bool return_code = false );
280 int16_t calc_justification( t_justification justification, uint8_t row );
281 void scroll_char(char c, uint8_t row);
282 void scroll_char(uint8_t* bitmap, uint8_t row);
283
284 // Variables ----------------------------------
285 #if defined( ARDUINO_ARCH_ESP8266 ) || defined( ARDUINO_ARCH_ESP32 )
286 Ticker animate;
287 #elif defined( ARDUINO_ARCH_TEENSY_3_X )
288 IntervalTimer animate;
289 #endif
290
291 const uint8_t display_padding_x = 1;
292 const uint8_t display_padding_y = 2;
293 const uint8_t display_width = display_padding_x + 5 + display_padding_x;
294 const uint8_t display_height = display_padding_y + 7 + display_padding_y;
295 const uint8_t extra_space_left = display_width;
296 const uint8_t leds_per_pixie = 70;
297 const uint8_t bit_table[2] = { 0, 255 };
298
299 volatile int16_t cursor_x;
300 volatile int16_t cursor_y;
301 volatile int16_t cursor_x_temp;
302 volatile int16_t cursor_y_temp;
303 t_justification justifications[8] = { LEFT, LEFT, LEFT, LEFT, LEFT, LEFT, LEFT, LEFT }; // Up to 8 rows
304 bool scrolling[8] = { false, false, false, false, false, false, false, false }; // Up to 8 rows
305 uint16_t scroll_frame_delay_ms = 10;
306 uint16_t scroll_hold_ms = 80;
307 t_scroll_type scroll_type = SMOOTH;
308
309 CRGB *color_map_out;
310 uint8_t *mask_out;
311 int16_t *xy_table;
312 uint32_t t_last;
313 CRGB print_col = CRGB( 0, 255, 0 );
314 uint8_t temp_code[5];
315
316 float max_V = 5;
317 uint16_t max_mA = 500;
318 uint8_t brightness_level = 255;
319
320 bool correct_gamma = false;
321 bool line_wrap = true;
322 bool just_wrapped = false;
323 bool custom_animation = false;
324
325 bool freeze = false;
326 bool ticker_running = false;
327 float fps_target = 60;
328
329 uint8_t pixie_pin;
330 uint8_t chars_x;
331 uint8_t chars_y;
332};
333
334#endif
This is the software documentation for using Pixie Chroma functions on Arduino! For full example usag...
void color_blur(fract8 blur_amount)
Blurs the color buffer in both axes by blur_amount.
void set_scroll_type(t_scroll_type type)
Sets the scroll behavior:
void shift_color_map_y(int16_t amount)
Shifts the color map data by amount on the Y axis. Useful for scrolling!
void print(uint8_t bitmap_col_1, uint8_t bitmap_col_2, uint8_t bitmap_col_3, uint8_t bitmap_col_4, uint8_t bitmap_col_5)
Prints a bitmap to the displays at the current cursor position, taking five uint8_t as input for the ...
void draw_line_mask(int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t value=255)
Draws a line in the mask buffer using Bresenham's line algorithm.
void set_color_animation_speed(float speed)
Used to scale the animation speed of animation ISRs that can use pix.animation_speed() to scale their...
void color(CRGB col)
Sets the entire color buffer to a CRGB value.
float animation_speed
Used by animation functions to scale the apparent speed of animation.
void write(uint8_t bitmap_col_1, uint8_t bitmap_col_2, uint8_t bitmap_col_3, uint8_t bitmap_col_4, uint8_t bitmap_col_5, uint8_t x_pos=0, uint8_t y_pos=0)
Writes a bitmap to a specified X and Y cursor position, taking five uint8_t as input for the column d...
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.
void set_color_animation(void(*action)(PixieChroma *, float))
Accepts a preset Color Animation or custom function to use for the animation ISR.
void print_color(CRGB col)
All print() calls after a print_color() will be colored with this value.
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.
uint16_t led_count
Stores the total number of physical LEDs, not including invisible pixels. This is calculated for you ...
void shift_color_map_x(int16_t amount, int16_t row=-1)
Shifts the color_map data by amount on the X axis. Useful for scrolling or justification!
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 free()
Unfreezes the current mask buffer in memory to allow showing updated text the next time show() is cal...
CRGB get_pixel_color(int32_t x, int32_t y)
Gets the RGB color value at a given pixel coordinate.
void blur(fract8 blur_amount)
Blurs the mask buffer in both axes by blur_amount.
void set_pixel_color(int32_t x, int32_t y, CRGB color)
Sets the RGB color value at a given pixel coordinate.
void println(uint8_t bitmap_col_1, uint8_t bitmap_col_2, uint8_t bitmap_col_3, uint8_t bitmap_col_4, uint8_t bitmap_col_5)
Prints a bitmap to the displays at the current cursor position, (taking five uint8_t as input for the...
void clear()
Clears (blackens) the current mask buffer and resets the cursor to 0,0.
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.
uint8_t get_pixel_mask(int32_t x, int32_t y)
Gets the mask value at a given pixel coordinate.
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 shift_mask_x(int16_t amount, int16_t row=-1)
Shifts the mask data by amount on the X axis. Useful for scrolling or justification!
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.
bool unit_tests()
Developer use - automated unit testing of PixieChroma code.
void color_blur_x(fract8 blur_amount)
Blurs the color buffer in the X axis by blur_amount.
void draw_line_color(int16_t x1, int16_t y1, int16_t x2, int16_t y2, CRGB color)
Draws a line in the color map using Bresenham's line algorithm.
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.
void set_pixel_mask(int32_t x, int32_t y, uint8_t value)
Sets the mask value at a given pixel coordinate.
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 shift_mask_y(int16_t amount)
Shifts the mask data by amount on the Y axis. Useful for scrolling!
void add_char(char chr, int16_t x_pos, int16_t y_pos)
Internal function for rendering a single char to the mask buffer.
void scroll_message(char *message, uint8_t row=0)
Scrolls a message across the matrix by constructing it one character at a time in the dead-space outs...
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 set_justification(t_justification justification, int16_t row=-1)
Sets the text justification globally, or by row.
void delay(uint32_t milliseconds)
Custom delay() function from FastLED that allows automatic refreshing of the displays during a delay(...
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.
uint16_t pixel_count
Stores the total number of pixels, including invisible pixels.
void hold()
Freezes the current mask buffer in memory to prevent showing unfinished text if show() automaticall f...