void generate_7_segments_display( const int32_t start_x, const int32_t start_y, const uint8_t number_of_digits, const char * color, const char * gnd_name )
{
static uint8_t display_id = 0;
const int8_t segments_position_offset[][2] =
{
{ 0, 0 },
{ 20, 20 },
{ 50, 20 },
{ 66, 0 },
{ 50, -15 },
{ 20, -15 },
{ 33, 0 },
};
const uint8_t distance_between_digits = 60;
char line[128];
for ( uint8_t digit = 0; digit < number_of_digits; ++digit )
{
uint32_t offset = ( digit * distance_between_digits );
for ( uint8_t segment = 0; segment < 7; ++segment )
{
int32_t x = start_x + segments_position_offset[segment][0];
int32_t y = start_y + segments_position_offset[segment][1] + offset;
snprintf( line, sizeof( line ),
" { \"type\": \"wokwi-led\", \"id\": \"7_%02hhu_%c_%02hhu\", \"top\": %4ld, \"left\": %4ld, %s\"attrs\": { \"color\": \"transparent\", \"lightColor\": \"%s\" } },",
display_id,
segment + 'A',
digit,
x,
y,
segment % 3 == 0 ? "\"rotate\": 90, " : " ",
color
);
Serial.println( line );
}
}
++display_id;
}
void generate_matrix_display(
const int32_t start_x,
const int32_t start_y,
const uint8_t spacing_x,
const uint8_t spacing_y,
const uint8_t number_of_rows,
const uint8_t number_of_columns,
const char * color,
const char * max7219_name
)
{
static uint8_t display_id = 0;
//const uint8_t distance_between_leds[2] = { 15, 15 };
//const uint8_t distance_between_leds[2] = { 30, 30 };
char line[256];
Serial.println( "----------------------------------------" );
for ( uint8_t row = 0; row < number_of_rows; ++row )
{
uint32_t x = start_x + ( row * spacing_x );
for ( uint8_t column = 0; column < number_of_columns; ++column )
{
uint32_t y = start_y + ( column * spacing_y );
snprintf( line, sizeof( line ),
" { \"type\": \"wokwi-led\", \"id\": \"m%hhu_r%hhuc%hhu\", \"top\": %4ld, \"left\": %4ld, \"attrs\": { \"color\": \"-\", \"lightColor\": \"%s\" } },",
display_id,
row,
column,
x,
y,
color
);
Serial.println( line );
}
}
Serial.println( "----------------------------------------" );
for ( uint8_t row = 0; row < number_of_rows; ++row )
{
for ( uint8_t column = 0; column < number_of_columns - 1; ++column )
{
snprintf( line, sizeof( line ),
" [ \"m%hhu_r%hhuc%hhu:C\", \"m%hhu_r%hhuc%hhu:C\", \"-black\", [] ],",
display_id,
row,
column,
display_id,
row,
column + 1
);
Serial.println( line );
}
}
for ( uint8_t row = 0; row < number_of_rows - 1; ++row )
{
for ( uint8_t column = 0; column < number_of_columns; ++column )
{
snprintf( line, sizeof( line ),
" [ \"m%hhu_r%hhuc%hhu:A\", \"m%hhu_r%hhuc%hhu:A\", \"-red\", [] ],",
display_id,
row,
column,
display_id,
row + 1,
column
);
Serial.println( line );
}
}
if ( max7219_name[0] != '\0' )
{
Serial.println();
for ( uint8_t row = 0, rows = min( 8, number_of_rows ); row < rows; ++row )
{
snprintf( line, sizeof( line ),
" [ \"m%hhu_r%hhuc0:C\", \"%s:DIG_%hhu\", \"grey\", [ \"h-10\", \"v%d\", \"*\", \"h15\" ] ],",
display_id,
row,
max7219_name,
row,
( rows - row - 1 ) * spacing_x
);
Serial.println( line );
}
Serial.println();
for ( int8_t column = 0, columns = min( 8, number_of_columns ); column < columns; ++column )
{
char segment_name[5];
if ( column < 7 )
{
segment_name[0] = column + 'A';
strcpy( segment_name + 1, "\", " );
}
else
{
strcpy( segment_name, "DP\"," );
}
snprintf( line, sizeof( line ),
" [ \"m%hhu_r%hhuc%hhu:A\", \"%s:SEG_%s \"grey\", [ \"v5\", \"*\", \"h10\"] ],",
display_id,
number_of_rows - 1,
(uint8_t)(6 - column) % 8,
max7219_name,
segment_name
);
Serial.println( line );
}
}
Serial.println( "----------------------------------------" );
++display_id;
}
void setup()
{
Serial.begin( 115200 );
pinMode( 3, OUTPUT );
//generate_7_segments_display( 0, 0, 8, "red", "nano:GND.1" );
//generate_matrix_display( 0, 0, 8, 8, "blue", "nano:GND.1" );
generate_matrix_display( 0, 0, 16, 16, 8, 8, "white", "m1" );
}
void loop() {
// put your main code here, to run repeatedly:
/*static uint8_t counter = 0;
static bool direction_changed = true;
static bool direction = true;
analogWrite( 3, counter );
if ( direction_changed == true )
{
direction_changed = false;
delay( 2000 );
Serial.println( direction == true ? "FadeIn" : "FadeOut" );
}
if ( ( direction == true && ++counter == UINT8_MAX ) || ( direction == false && --counter == 0 ) )
{
direction = !direction;
direction_changed = true;
}
delay( 10 );*/
}