Create a gist now

Instantly share code, notes, and snippets.

@ep1cman /
Last active Aug 29, 2015

What would you like to do?
7 Segment character value generator
#The order segments are connected to the shift register (D = dot)
input = ['a','b','c','d','e','f','g','D']
reverse = True #Depends on direction of outputs/shifting
negate = True #Common Cathode = False Common Anode = True
characters = [("abcdef", '0/O'),
("bc", '1/I'),
("abdeg", '2'),
("abcdg", '3'),
("bcfg", '4'),
("acdfg", '5/s'),
("acdefg", '6'),
("abc", '7'),
("abcfg", '9/g'),
("abcefg", 'A'),
("cdefg", 'b'),
("deg", 'c'),
("adef", 'C'),
("bcdeg", 'd'),
("adefg", 'E'),
("aefg", 'F'),
("acdef", 'G'),
("bcefg", 'H'),
("bcd", 'J'),
("def", 'L'),
("ceg", 'n'),
("cdeg", 'o'),
("abefg", 'P'),
("abcfg", 'q'),
("eg", 'r'),
("defg", 't'),
("cde", 'u'),
("bcdef", 'U'),
("bcdfg", 'y'),
("D", '.')]
for character in characters:
output = 0
for segment in character[0]:
if reverse:
output |= (1<<input.index(segment))
output |= (128>>input.index(segment))
output = ~output & 0xFF
print "Character: " + character[1]
print "Hex: " + "0x{0:02X}".format(output)
print "Binary: "+"{0:08b}".format(output)
print ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment