Skip to content

Instantly share code, notes, and snippets.

@MaverickEsq
Created April 10, 2022 11:31
Show Gist options
  • Save MaverickEsq/04caa98988febbc7af2f9eb63a29d370 to your computer and use it in GitHub Desktop.
Save MaverickEsq/04caa98988febbc7af2f9eb63a29d370 to your computer and use it in GitHub Desktop.
rotates character map for a 7 segment display
#!/usr/bin/perl
# rotates a character map for an 8 segment display so
# that you can generate a character map for an
# upside down display.
#
# Used to make a header, kept in case I need to rotate something else?
#my @map = (0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7f, 0x7C, 0x39, 0x58, 0x3f, 0x5E, 0x79, 0x71, 0x7d, 0x76, 0x74, 0x06, 0x1f, 0x76, 0x38, 0x06, 0x54, 0x3f, 0x5c, 0x73, 0x50, 0x6d, 0x3e, 0x3e, 0x66, 0x5b, 0x40, 0x08, 0x00);
my %map = (
'0' => 0x3f,
'1' => 0x06,
'2' => 0x5b,
'3' => 0x4f,
'4' => 0x66,
'5' => 0x6d,
'6' => 0x7d,
'7' => 0x07,
'8' => 0x7f,
'9' => 0x6f,
'A' => 0x77,
'B' => 0x7f,
'b' => 0x7C,
'C' => 0x39,
'c' => 0x58,
'D' => 0x3f,
'd' => 0x5E,
'E' => 0x79,
'F' => 0x71,
'G' => 0x7d,
'H' => 0x76,
'h' => 0x74,
'I' => 0x06,
'J' => 0x1f,
'K' => 0x76,
'L' => 0x38,
'l' => 0x06,
'n' => 0x54,
'O' => 0x3f,
'o' => 0x5c,
'P' => 0x73,
'r' => 0x50,
'S' => 0x6d,
'U' => 0x3e,
'V' => 0x3e,
'Y' => 0x66,
'Z' => 0x5b,
'-' => 0x40,
'_' => 0x08,
' ' => 0x00
);
foreach $char (sort keys %map) {
print "'$char': " . conv($map{$char}) . "\n";
#print "'$char' => " . sprintf('%08b', $map{$char}) . "\n";
}
sub conv {
my @in = split //, sprintf '%08b', shift(@_);
return "0x" . sprintf('%02X', eval "0b" . join('', $in[0], $in[1], $in[5], $in[6], $in[7], $in[2], $in[3], $in[4]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment