This repository has been archived by the owner on Nov 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scr.py
67 lines (58 loc) · 1.93 KB
/
scr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import gaugette.ssd1306
import time
import sys
import spidev
import font5x8
from gaugette.fonts import verdana_15
from gaugette.fonts import verdana_24
from subprocess import Popen, PIPE
RESET_PIN = 0 #15
DC_PIN = 1 #16
def show_scr(scrollinglist,index):
scrollinglist.ssd1306.display_block(scrollinglist.bitmaps[index],0,0,scrollinglist.cols)
scrollinglist.position=index*32
def draw_text(bmp, x, y, string):
font=font5x8.Font5x8
font_bytes = font.bytes
font_rows = font.rows
font_cols = font.cols
for c in string:
p = ord(c) * font_cols
for col in range(0,font_cols):
mask = font_bytes[p]
p+=1
for row in range(0,8):
draw_pixel(bmp,x,y+row,mask & 0x1)
mask >>= 1
x += 1
def draw_pixel(bmp, x, y, on=True):
if (x<0 or x>=bmp.cols or y<0 or y>=bmp.rows):
return
mem_col = x
mem_row = y / 8
bit_mask = 1 << (y % 8)
offset = mem_row + bmp.rows/8 * mem_col
if on:
bmp.data[offset] |= bit_mask
else:
bmp.data[offset] &= (0xFF - bit_mask)
led = gaugette.ssd1306.SSD1306(reset_pin=RESET_PIN, dc_pin=DC_PIN)
led.begin()
scr = gaugette.ssd1306.SSD1306.ScrollingList(led,[""],verdana_15)
bmp=gaugette.ssd1306.SSD1306.Bitmap(1200,32) #new bmp of fixed width
draw_text(bmp,0,0,"TITLE")
draw_text(bmp,0,16,"Scroller /\ (ascii set)")
draw_text(bmp,0,24,"Stationary text")
scr.bitmaps=[bmp]
y=1 #column for scroller
char_sep=15 #separation between characters
alph=gaugette.ssd1306.SSD1306.Bitmap(95*char_sep+128,8) #buffer holds alpha chars
for i in range(0,95): #draw alpha chars in buffer
draw_text(alph,64+i*char_sep,0,chr(i+32))
wid=alph.cols-128
scr.ssd1306.display_block(scr.bitmaps[0],0,0,128,0) #show screen
while True:
for i in range(0,wid,1):
scr.ssd1306.display_block(alph,y*8,0,128,i)
for i in range(wid,0,-1):
scr.ssd1306.display_block(alph,y*8,0,128,i)