Last active
October 27, 2016 17:10
-
-
Save masimplo/799bdb099ad879829736e9345c0d5747 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Font derived from LED Matrix Studio file: fontv.h | |
| # | |
| # The first element in each array variable is the width of the character | |
| # The remaining 8 elements are the decimal value for each row of | |
| # the character to display | |
| # | |
| # EG for the 'A' character | |
| # | |
| # | *** | = 011100(28) | |
| # |* * | = 100010(34) | |
| # |* * | = 100010(34) | |
| # |* * | = 100010(34) | |
| # |***** | = 111110(62) | |
| # |* * | = 100010(34) | |
| # |* * | = 100010(34) | |
| # | | = 000000(0) | |
| # the ascii value of the character is used for the array index value | |
| # eg 65 for 'A' | |
| # | |
| # initialise 9 x 128 array with 0 | |
| array=[[0 for i in xrange(9)] for i in xrange(128)] | |
| # | |
| # define ascii characters 32 to 126 | |
| # | |
| array[32] = [5, 0, 0, 0, 0, 0, 0, 0, 0] # ASCII 32 | |
| array[33] = [2, 2, 2, 2, 2, 0, 0, 2, 0] # ! ASCII 33 | |
| array[34] = [4, 10, 10, 10, 0, 0, 0, 0, 0] # " ASCII 34 | |
| array[35] = [6, 20, 20, 62, 20, 62, 20, 20, 0] # # ASCII 35 | |
| array[36] = [6, 8, 30, 40, 28, 10, 60, 8, 0] # $ ASCII 36 | |
| array[37] = [6, 48, 50, 4, 8, 16, 38, 6, 0] # % ASCII 37 | |
| array[38] = [6, 24, 36, 40, 16, 42, 36, 26, 0] # & ASCII 38 | |
| array[39] = [3, 6, 2, 4, 0, 0, 0, 0, 0] # ' ASCII 39 | |
| array[40] = [4, 2, 4, 8, 8, 8, 4, 2, 0] # ( ASCII 40 | |
| array[41] = [4, 8, 4, 2, 2, 2, 4, 8, 0] # ) ASCII 41 | |
| array[42] = [6, 0, 8, 42, 28, 42, 8, 0, 0] # * ASCII 42 | |
| array[43] = [6, 0, 8, 8, 62, 8, 8, 0, 0] # + ASCII 43 | |
| array[44] = [3, 0, 0, 0, 0, 0, 6, 2, 4] # , ASCII 44 | |
| array[45] = [6, 0, 0, 0, 62, 0, 0, 0, 0] # - ASCII 45 | |
| array[46] = [3, 0, 0, 0, 0, 0, 6, 6, 0] # . ASCII 46 | |
| array[47] = [6, 0, 2, 4, 8, 16, 32, 0, 0] # / ASCII 47 | |
| array[48] = [6, 28, 34, 38, 42, 50, 34, 28, 0] # 0 ASCII 48 | |
| array[49] = [4, 4, 12, 4, 4, 4, 4, 14, 0] # 1 ASCII 49 | |
| array[50] = [6, 28, 34, 2, 4, 8, 16, 62, 0] # 2 ASCII 50 | |
| array[51] = [6, 62, 4, 8, 4, 2, 34, 28, 0] # 3 ASCII 51 | |
| array[52] = [6, 4, 12, 20, 36, 62, 4, 4, 0] # 4 ASCII 52 | |
| array[53] = [6, 62, 32, 60, 2, 2, 34, 28, 0] # 5 ASCII 53 | |
| array[54] = [6, 12, 16, 32, 60, 34, 34, 28, 0] # 6 ASCII 54 | |
| array[55] = [6, 62, 2, 4, 8, 16, 16, 16, 0] # 7 ASCII 55 | |
| array[56] = [6, 28, 34, 34, 28, 34, 34, 28, 0] # 8 ASCII 56 | |
| array[57] = [6, 28, 34, 34, 30, 2, 4, 24, 0] # 9 ASCII 57 | |
| array[58] = [3, 0, 6, 6, 0, 6, 6, 0, 0] # : ASCII 58 | |
| array[59] = [3, 0, 6, 6, 0, 6, 2, 4, 0] # ; ASCII 59 | |
| array[60] = [5, 2, 4, 8, 16, 8, 4, 2, 0] # < ASCII 60 | |
| array[61] = [6, 0, 0, 62, 0, 62, 0, 0, 0] # = ASCII 61 | |
| array[62] = [5, 16, 8, 4, 2, 4, 8, 16, 0] # > ASCII 62 | |
| array[63] = [6, 28, 34, 2, 4, 8, 0, 8, 0] # ? ASCII 63 | |
| array[64] = [6, 28, 34, 2, 26, 42, 42, 28, 0] # @ ASCII 64 | |
| array[65] = [6, 28, 34, 34, 34, 62, 34, 34, 0] # A ASCII 65 | |
| array[66] = [6, 60, 34, 34, 60, 34, 34, 60, 0] # B ASCII 66 | |
| array[67] = [6, 28, 34, 32, 32, 32, 34, 28, 0] # C ASCII 67 | |
| array[68] = [6, 56, 36, 34, 34, 34, 36, 56, 0] # D ASCII 68 | |
| array[69] = [6, 62, 32, 32, 60, 32, 32, 62, 0] # E ASCII 69 | |
| array[70] = [6, 62, 32, 32, 60, 32, 32, 32, 0] # F ASCII 70 | |
| array[71] = [6, 28, 34, 32, 46, 34, 34, 30, 0] # G ASCII 71 | |
| array[72] = [6, 34, 34, 34, 62, 34, 34, 34, 0] # H ASCII 72 | |
| array[73] = [4, 14, 4, 4, 4, 4, 4, 14, 0] # I ASCII 73 | |
| array[74] = [6, 14, 4, 4, 4, 4, 36, 24, 0] # J ASCII 74 | |
| array[75] = [6, 34, 36, 40, 48, 40, 36, 34, 0] # K ASCII 75 | |
| array[76] = [6, 32, 32, 32, 32, 32, 32, 62, 0] # L ASCII 76 | |
| array[77] = [6, 34, 54, 42, 42, 34, 34, 34, 0] # M ASCII 77 | |
| array[78] = [6, 34, 34, 50, 42, 38, 34, 34, 0] # N ASCII 78 | |
| array[79] = [6, 28, 34, 34, 34, 34, 34, 28, 0] # O ASCII 79 | |
| array[80] = [6, 60, 34, 34, 60, 32, 32, 32, 0] # P ASCII 80 | |
| array[81] = [6, 28, 34, 34, 34, 42, 36, 26, 0] # Q ASCII 81 | |
| array[82] = [6, 60, 34, 34, 60, 40, 36, 34, 0] # R ASCII 82 | |
| array[83] = [6, 30, 32, 32, 28, 2, 2, 60, 0] # S ASCII 83 | |
| array[84] = [6, 62, 8, 8, 8, 8, 8, 8, 0] # T ASCII 84 | |
| array[85] = [6, 34, 34, 34, 34, 34, 34, 28, 0] # U ASCII 85 | |
| array[86] = [6, 34, 34, 34, 34, 34, 20, 8, 0] # V ASCII 86 | |
| array[87] = [6, 34, 34, 34, 42, 42, 42, 20, 0] # W ASCII 87 | |
| array[88] = [6, 34, 34, 20, 8, 20, 34, 34, 0] # X ASCII 88 | |
| array[89] = [6, 34, 34, 34, 20, 8, 8, 8, 0] # Y ASCII 89 | |
| array[90] = [6, 62, 2, 4, 8, 16, 32, 62, 0] # Z ASCII 90 | |
| array[91] = [4, 14, 8, 8, 8, 8, 8, 14, 0] # [ ASCII 91 | |
| array[92] = [6, 0, 32, 16, 8, 4, 2, 0, 0] # \ ASCII 92 | |
| array[93] = [4, 14, 2, 2, 2, 2, 2, 14, 0] # ] ASCII 93 | |
| array[94] = [6, 8, 20, 34, 0, 0, 0, 0, 0] # ^ ASCII 94 | |
| array[95] = [6, 0, 0, 0, 0, 0, 0, 62, 0] # _ ASCII 95 | |
| array[96] = [4, 8, 4, 2, 0, 0, 0, 0, 0] # ` ASCII 96 | |
| array[97] = [6, 0, 0, 28, 2, 30, 34, 30, 0] # a ASCII 97 | |
| array[98] = [6, 32, 32, 44, 50, 34, 34, 60, 0] # b ASCII 98 | |
| array[99] = [6, 0, 0, 28, 32, 32, 34, 28, 0] # c ASCII 99 | |
| array[100] = [6, 2, 2, 26, 38, 34, 34, 30, 0] # d ASCII 100 | |
| array[101] = [6, 0, 0, 28, 34, 62, 32, 28, 0] # e ASCII 101 | |
| array[102] = [6, 12, 18, 16, 56, 16, 16, 16, 0] # f ASCII 102 | |
| array[103] = [6, 0, 0, 30, 34, 34, 30, 2, 28] # g ASCII 103 | |
| array[104] = [6, 32, 32, 44, 50, 34, 34, 34, 0] # h ASCII 104 | |
| array[105] = [2, 2, 0, 2, 2, 2, 2, 2, 0] # i ASCII 105 | |
| array[106] = [5, 2, 0, 6, 2, 2, 2, 18, 12] # j ASCII 106 | |
| array[107] = [5, 16, 16, 18, 20, 24, 20, 18, 0] # k ASCII 107 | |
| array[108] = [4, 12, 4, 4, 4, 4, 4, 14, 0] # l ASCII 108 | |
| array[109] = [6, 0, 0, 52, 42, 42, 34, 34, 0] # m ASCII 109 | |
| array[110] = [6, 0, 0, 44, 50, 34, 34, 34, 0] # n ASCII 110 | |
| array[111] = [6, 0, 0, 28, 34, 34, 34, 28, 0] # o ASCII 111 | |
| array[112] = [6, 0, 0, 60, 34, 34, 60, 32, 32] # p ASCII 112 | |
| array[113] = [6, 0, 0, 26, 38, 34, 30, 2, 6] # q ASCII 113 | |
| array[114] = [6, 0, 0, 44, 50, 32, 32, 32, 0] # r ASCII 114 | |
| array[115] = [6, 0, 0, 30, 32, 28, 2, 60, 0] # s ASCII 115 | |
| array[116] = [6, 16, 16, 56, 16, 16, 18, 12, 0] # t ASCII 116 | |
| array[117] = [6, 0, 0, 34, 34, 34, 38, 26, 0] # u ASCII 117 | |
| array[118] = [6, 0, 0, 34, 34, 34, 20, 8, 0] # v ASCII 118 | |
| array[119] = [6, 0, 0, 34, 34, 42, 42, 20, 0] # w ASCII 119 | |
| array[120] = [6, 0, 0, 34, 20, 8, 20, 34, 0] # x ASCII 120 | |
| array[121] = [6, 0, 0, 34, 34, 34, 30, 2, 28] # y ASCII 121 | |
| array[122] = [6, 0, 0, 62, 4, 8, 16, 62, 0] # z ASCII 122 | |
| array[123] = [4, 2, 4, 4, 8, 4, 4, 2, 0] # { ASCII 123 | |
| array[124] = [2, 2, 2, 2, 2, 2, 2, 2, 0] # | ASCII 124 | |
| array[125] = [4, 8, 4, 4, 2, 4, 4, 8, 0] # } ASCII 125 | |
| array[126] = [6, 0, 16, 42, 42, 4, 0, 0, 0] # ~ ASCII 126 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ################################################### | |
| # ldp python module (ldp.py) | |
| # use: import ldp (in your script) | |
| # A set of functions to make it easier to interface | |
| # with Embedded Adventures' 80x8 led matrix LDP-8008 | |
| # By Pete Goss 14/1/2014 | |
| ################################################### | |
| # connect Raspberry Pi GPIO to J1 on LDP-8008 | |
| ################################################### | |
| # GPIO pin LDP-8008 pin | |
| # 3 ------------> 2 A (Row address) | |
| # 5 ------------> 4 B (Row address) | |
| # 6 ------------> 5 GND | |
| # 7 ------------> 6 C (Row address) | |
| # 8 ------------> 7 EN (Enable Display) | |
| # 10 ------------> 8 D (Row address) | |
| # 11 ------------> 9 \R1 (Red Led) | |
| # 12 ------------> 10 \G1 (Green Led) | |
| # 13 ------------> 14 L (Latch) | |
| # 15 ------------> 16 S (Shift) | |
| ################################################### | |
| import RPi.GPIO as gpio | |
| gpio.setwarnings(False) | |
| gpio.setmode(gpio.BOARD) | |
| ################################################### | |
| # give the gpio pins labels that match the LDP-8008 | |
| ################################################### | |
| R1=11 | |
| G1=12 | |
| EN=8 | |
| A=3 | |
| B=5 | |
| C=7 | |
| D=10 | |
| L=13 | |
| S=15 | |
| #################################### | |
| # init function | |
| # usage: ldp.init() | |
| # function initialises the LDP-8008 | |
| # use once at beginning of script | |
| #################################### | |
| def init(): | |
| # set GPIO pins as outputs | |
| gpio.setup(R1,gpio.OUT) | |
| gpio.setup(G1,gpio.OUT) | |
| gpio.setup(EN,gpio.OUT) | |
| gpio.setup(A,gpio.OUT) | |
| gpio.setup(B,gpio.OUT) | |
| gpio.setup(C,gpio.OUT) | |
| gpio.setup(D,gpio.OUT) | |
| gpio.setup(L,gpio.OUT) | |
| gpio.setup(S,gpio.OUT) | |
| #initialise the output pins | |
| gpio.output(R1,1) | |
| gpio.output(G1,1) | |
| gpio.output(S,1) | |
| gpio.output(L,0) | |
| gpio.output(EN,0) | |
| clear() | |
| #################################### | |
| # end init function | |
| #################################### | |
| #################################### | |
| # clear function | |
| # usage: ldp.clear() | |
| # function sets the shift register | |
| # bits to blank and turns off display | |
| #################################### | |
| def clear(): | |
| gpio.output(R1,1) | |
| gpio.output(G1,1) | |
| for i in range(80): | |
| shift() | |
| displayoff() | |
| #################################### | |
| # end init function | |
| #################################### | |
| #################################### | |
| # shift function | |
| # usage: ldp.shift() | |
| # function shifts the current led colour | |
| # into the first column of the register | |
| #################################### | |
| def shift(): | |
| gpio.output(S,1) | |
| gpio.output(S,0) | |
| gpio.output(S,1) | |
| #################################### | |
| # end shift function | |
| #################################### | |
| #################################### | |
| # colour function | |
| # usage: ldp.colour(colour_value) | |
| # sets the current led colour | |
| # 0=blank 1=red 2=green 3=orange | |
| #################################### | |
| def colour(n): | |
| if n == 3: #orange | |
| gpio.output(R1,0) | |
| gpio.output(G1,0) | |
| elif n == 2: #green | |
| gpio.output(R1,1) | |
| gpio.output(G1,0) | |
| elif n == 1: #red | |
| gpio.output(R1,0) | |
| gpio.output(G1,1) | |
| else: # off | |
| gpio.output(R1,1) | |
| gpio.output(G1,1) | |
| #################################### | |
| # end colour function | |
| #################################### | |
| #################################### | |
| # colourshift function | |
| # usage: ldp.colourshift(colour_value) | |
| # sets the current led colour | |
| # and also shifts it into the register | |
| # 0=blank 1=red 2=green 3=orange | |
| #################################### | |
| def colourshift(n): | |
| colour(n) | |
| shift() | |
| #################################### | |
| # end colour function | |
| #################################### | |
| #################################### | |
| # showrow function | |
| # usage: ldp.showrow(row_value) | |
| # displays the register on a row | |
| # row_value = 0-7 | |
| #################################### | |
| def showrow(n): | |
| displayoff() | |
| if n == 7: | |
| gpio.output(A,1) | |
| gpio.output(B,1) | |
| gpio.output(C,1) | |
| gpio.output(D,0) | |
| elif n == 6: | |
| gpio.output(A,0) | |
| gpio.output(B,1) | |
| gpio.output(C,1) | |
| gpio.output(D,0) | |
| elif n == 5: | |
| gpio.output(A,1) | |
| gpio.output(B,0) | |
| gpio.output(C,1) | |
| gpio.output(D,0) | |
| elif n == 4: | |
| gpio.output(A,0) | |
| gpio.output(B,0) | |
| gpio.output(C,1) | |
| gpio.output(D,0) | |
| elif n == 3: | |
| gpio.output(A,1) | |
| gpio.output(B,1) | |
| gpio.output(C,0) | |
| gpio.output(D,0) | |
| elif n == 2: | |
| gpio.output(A,0) | |
| gpio.output(B,1) | |
| gpio.output(C,0) | |
| gpio.output(D,0) | |
| elif n == 1: | |
| gpio.output(A,1) | |
| gpio.output(B,0) | |
| gpio.output(C,0) | |
| gpio.output(D,0) | |
| else: | |
| gpio.output(A,0) | |
| gpio.output(B,0) | |
| gpio.output(C,0) | |
| gpio.output(D,0) | |
| # latch the data | |
| gpio.output(L,1) | |
| gpio.output(L,0) | |
| # display the row | |
| displayon() | |
| #################################### | |
| # end showrow function | |
| #################################### | |
| #################################### | |
| # displayoff function | |
| # usage: ldp.displayoff() | |
| # turns off the display | |
| #################################### | |
| def displayoff(): | |
| gpio.output(EN,0) | |
| #################################### | |
| # end displayoff function | |
| #################################### | |
| #################################### | |
| # displayon function | |
| # usage: ldp.displayon() | |
| # turns on the display | |
| #################################### | |
| def displayon(): | |
| gpio.output(EN,1) | |
| #################################### | |
| # end displayon function | |
| #################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import sys | |
| import time | |
| import fontv | |
| import ldp | |
| # the matrix is a representation of the led's that are lit on the 80x8 display | |
| # | |
| matrix=[[0 for i in xrange(80)] for i in xrange(8)] | |
| # | |
| # function to shift left all the vaules of the matrix array | |
| # this allows us to put new data in the first column | |
| # | |
| def shiftmatrix(): | |
| for row in range(8): | |
| for col in range(79,0,-1): | |
| matrix[row][col]=matrix[row][col-1] | |
| # end def | |
| # function to read the matrix array and output the values to the display device | |
| # | |
| def showmatrix(): | |
| ldp.displayoff() | |
| for row in reversed(range(8)): | |
| for col in reversed(range(80)): | |
| ldp.colourshift(matrix[row][col]) | |
| ldp.showrow(row) | |
| # end def | |
| # | |
| # Main | |
| # | |
| # initialise the display | |
| # | |
| ldp.init() | |
| # | |
| # assign the command line args for the text and colour | |
| # | |
| textinput=str(sys.argv[1]) | |
| colour=int(sys.argv[2]) | |
| # append extra characters to text input to allow for wrap-around | |
| textinput+=' :: ' | |
| # save the ascii values of the input characters into the inputarray | |
| # the font module uses the ascii value to index the font array | |
| inputarray=[] | |
| for char in textinput: | |
| inputarray.append(ord(char)) | |
| # dotarray is 8 X n | |
| # n is determined by the number of characters multiplyed by 8 | |
| # n will be len(dotarray[0]) after filling dotarray from characters | |
| # in the inputarray | |
| # | |
| dotarray=[[] for i in xrange(8)] | |
| # | |
| # fill the dot array with the colour digits | |
| # this is the dot pattern that we want to show | |
| # | |
| for row in range(8): | |
| for ascii in inputarray: | |
| # get the width of the character from the first element of the font variable | |
| width=fontv.array[ascii][0] | |
| binary='{0:{fill}{align}{width}{base}}'.format(fontv.array[ascii][row+1],base='b',fill='0',align='>',width=width) | |
| for digit in range(width): | |
| if binary[digit] == '0': | |
| dotarray[row].append(0) | |
| else: | |
| dotarray[row].append(colour) | |
| # | |
| # Continually output to the display until Ctrl-C | |
| # | |
| while True: | |
| try: | |
| # loop around each column in the dotarray | |
| for col in range(len(dotarray[0])): | |
| for row in range(8): | |
| # copy the current dotarray column values to the first column in the matrix | |
| matrix[row][0]=(dotarray[row][col]) | |
| # now that we have updated the matrix lets show it | |
| showmatrix() | |
| # shift the matrix left ready for the next column | |
| shiftmatrix() | |
| except KeyboardInterrupt: | |
| ldp.clear() | |
| print "Finished" | |
| sys.exit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import sys | |
| import time | |
| import fontv | |
| import ldp | |
| # the matrix is a representation of the led's that are lit on the 80x8 display | |
| # | |
| matrix=[[0 for i in xrange(80)] for i in xrange(8)] | |
| # | |
| # function to shift left all the vaules of the matrix array | |
| # this allows us to put new data in the first column | |
| # | |
| def shiftmatrix(): | |
| for row in range(8): | |
| for col in range(79,0,-1): | |
| matrix[row][col]=matrix[row][col-1] | |
| # end def | |
| # function to read the matrix array and output the values to the display device | |
| # | |
| def showmatrix(): | |
| for row in range(8): | |
| for col in range(80): | |
| ldp.colourshift(matrix[row][col]) | |
| ldp.showrow(row) | |
| # end def | |
| # | |
| # Main | |
| # | |
| # initialise the display | |
| # | |
| ldp.init() | |
| displaywidth=80 | |
| totalwidth=0 | |
| # | |
| # assign the command line args for the text and colour | |
| # | |
| textinput=str(sys.argv[1]) | |
| colour=int(sys.argv[2]) | |
| # save the ascii values of the input characters into the inputarray | |
| # the font module uses the ascii value to index the font array | |
| inputarray=[] | |
| for char in textinput: | |
| inputarray.append(ord(char)) | |
| # dotarray is 8 X n | |
| # n is determined by the number of characters multiplyed by 8 | |
| # n will be len(dotarray[0]) after filling dotarray from characters | |
| # in the inputarray | |
| # | |
| dotarray=[[] for i in xrange(8)] | |
| # | |
| # fill the dot array with the colour digits | |
| # this is the dot pattern that we want to show | |
| # | |
| for row in range(8): | |
| for ascii in inputarray: | |
| # get the width of the character from the first element of the font variable | |
| width=fontv.array[ascii][0] | |
| binary='{0:{fill}{align}{width}{base}}'.format(fontv.array[ascii][row+1],base='b',fill='0',align='>',width=width) | |
| for digit in range(width): | |
| if binary[digit] == '0': | |
| dotarray[row].append(0) | |
| else: | |
| dotarray[row].append(colour) | |
| totalwidth=len(dotarray[0]) | |
| if totalwidth > displaywidth: | |
| print 'Message is Larger than the Display' | |
| sys.exit() | |
| offset=int((displaywidth - totalwidth) / 2) | |
| # Fill the matrix initially with offset spaces to centre align the message | |
| # | |
| for col in range(offset): | |
| for row in range(8): | |
| matrix[row][col]=0 | |
| # now fill the rest of the matrix with the dotarray | |
| for col in range(totalwidth): | |
| for row in range(8): | |
| # copy the current dotarray column values to the first column in the matrix | |
| matrix[row][offset+col]=(dotarray[row][col]) | |
| # | |
| # Continually output to the display until Ctrl-C | |
| # | |
| while True: | |
| try: | |
| # now that we have updated the matrix lets show it | |
| showmatrix() | |
| #time.sleep(0.0001) | |
| except KeyboardInterrupt: | |
| ldp.clear() | |
| print "Finished" | |
| sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment