Skip to content

Instantly share code, notes, and snippets.

@sooop

sooop/print_digits.py

Last active Sep 6, 2017
Embed
What would you like to do?
display LCD Digits
def present(s, digits):
masks = ('02356789', '045689', '01234789', '2345689', '0268', '013456789', '0235689')
result = []
h = lambda x: ' '.join(' ' + ('-' if d in masks[x] else ' ') * s + ' '\
for d in digits)
v = lambda x: ' '.join(('|' if d in masks[x] else ' ') + ' ' * s +\
('|' if d in masks[x+1] else ' ') for d in digits)
result.append(h(0))
result += [v(1)] * s
result.append(h(3))
result += [v(4)] * s
result.append(h(6))
print('\n'.join(result))
present(3, "0123456789")
@sooop

This comment has been minimized.

Copy link
Owner Author

@sooop sooop commented Sep 6, 2017

result:

 ---         ---   ---         ---   ---   ---   ---   --- 
|   |     |     |     | |   | |     |         | |   | |   |
|   |     |     |     | |   | |     |         | |   | |   |
|   |     |     |     | |   | |     |         | |   | |   |
             ---   ---   ---   ---   ---         ---   --- 
|   |     | |         |     |     | |   |     | |   |     |
|   |     | |         |     |     | |   |     | |   |     |
|   |     | |         |     |     | |   |     | |   |     |
 ---         ---   ---         ---   ---         ---   --- 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment