def main(): frames = processImage('/home/pi/rpi-matrix-gif/myGIF.gif') matrix = Adafruit_RGBmatrix(32, 1) while True: for f in frames: matrix.SetImage(f.im.id, 0, 0) time.sleep(0.1)
def __init__(self): self.capabilities(MATRIX_WIDTH, MATRIX_HEIGHT, mode="RGB") # Use Adafruit's RGB Matrix class from rgbmatrix import Adafruit_RGBmatrix self._matrix = Adafruit_RGBmatrix(32, 1)
def main(argv): # init led matrix matrix = Adafruit_RGBmatrix(32, 1) matrix.Clear() # file name inputfile = '' try: opts, args = getopt.getopt(argv, "hi:o:", ["ifile="]) except getopt.GetoptError: print 'test.py -i <inputfile>' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'test.py -i <inputfile>' sys.exit() elif opt in ("-i", "--ifile"): inputfile = arg # play print 'Input file is ', inputfile image = Image.open(inputfile) image.load() matrix.SetImage(image.im.id, 0, 1) time.sleep(10.0) matrix.Clear()
def loop(): from rgbmatrix import Adafruit_RGBmatrix matrix = Adafruit_RGBmatrix(MATRIX_SIZE,1) while(True): run(matrix) time.sleep(REFRESH_INTERVAL) matrix.Clear()
class InfoMatrix(object): def __init__(self): self._matrix = Adafruit_RGBmatrix(32, 1) self._font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 12) @staticmethod def _image_draw(): image = Image.new('RGB', (32, 32), 'black') draw = ImageDraw.Draw(image) return image, draw def update_weather(self, temp, percip): image, draw = self._image_draw() draw.text( (1, 0), '{0} f'.format(int(round(temp))), (255, 0, 0), font=self._font) draw.text( (1, 13), percip, (255, 0, 0), font=self._font) self._matrix.Clear() self._matrix.SetImage(image.im.id, 0, 0) def write_bus(self, route, prediction): image, draw = self._image_draw() draw.text((0, 0), '{0}:'.format(route), (255, 0, 0), font=self._font) draw.text((0, 13), prediction, (255, 0, 0), font=self._font) self._matrix.Clear() self._matrix.SetImage(image.im.id, 0, 0)
class drawing_app_matrix: def __init__(self): # Initialize LED Matrix self.matrix = Adafruit_RGBmatrix(32, 1) def main(self, arg1, arg2): self.matrix.Clear() # INPUT pix = arg1 rainbow = arg2 # end INPUT #print_to_matrix_default(canvas_pix) if rainbow: for x in range(0, 32): for y in range(0, 32): if pix[x][y] == 1: self.matrix.SetPixel(x, y, randint(0, 255), randint(0, 255), randint(0, 255)) else: for x in range(0, 32): for y in range(0, 32): if pix[x][y] == 1: self.matrix.SetPixel(x, y, 255, 0, 0) def clear_matrix(self): self.matrix.Clear() if __name__ == "__main__": main(sys.argv[1], sys.argv[2])
class input_triggered_matrix: def __init__(self): # Initialize LED Matrix self.matrix = Adafruit_RGBmatrix(32, 1) def main(self, arg1, arg2): # INPUT word = arg1 score = arg2 # end INPUT # Initialize canvas canvas_pix = numpy.zeros((32, 32)) # Word input -> canvas canvas_pix = overlayAt(1, 4, stringtopix(word), canvas_pix, 1) # Scoreboard -> canvas canvas_pix = overlayAt(1, 16, stringtopix("Score:"), canvas_pix, 1) # Score input -> canvas canvas_pix = overlayAt(1, 24, stringtopix(str(score)), canvas_pix, 1) # print_to_matrix_default(canvas_pix) for x in range(0,32): for y in range(0,32): if canvas_pix[x][y] == 1: self.matrix.SetPixel(x,y,255,0,0) # time.sleep(1.0) # matrix.Clear() def clear_matrix(self): self.matrix.Clear() def clear_word(self,score): # Initialize canvas canvas_pix = numpy.zeros((32, 32)) # Word input -> canvas #canvas_pix = overlayAt(1, 4, stringtopix(word), canvas_pix, 1) # Scoreboard -> canvas canvas_pix = overlayAt(1, 16, stringtopix("Score:"), canvas_pix, 1) # Score input -> canvas canvas_pix = overlayAt(1, 24, stringtopix(str(score)), canvas_pix, 1) # print_to_matrix_default(canvas_pix) for x in range(0,32): for y in range(0,32): if canvas_pix[x][y] == 1: self.matrix.SetPixel(x,y,255,0,0) if __name__ == "__main__": main(sys.argv[1], sys.argv[2])
def launch_matrix(message_queue): #setup the matrix and screen buffer matrix = Adafruit_RGBmatrix(height, chain_len) # rows, chain length image = Image.new('RGB', (width, height)) draw = ImageDraw.Draw(image) message_list = [] #initialize the message_list to empty. # Make two message slots (two rows of text) message_slots = [] for y in xrange(0, 2): message_slots.append(MessageSlot(0, y * font_height, StillFrames)) # Set times for frame counting current_time = 0.0 prev_time = 0.0 # Delay frames from when last message was shown to put default up frame_delay = 40 # Frames since last message was displayed frames_since_message = frame_delay while True: # Draw empty background rectangle draw.rectangle((0, 0, width, height), fill=(0, 0, 0)) # Empty the inbound queue while (not message_queue.empty()): message_list.append(message_queue.get()) # Find out if we are displaying anything and draw if we are. displaying_messages = False for message_slot in message_slots: if (message_slot.has_message()): displaying_messages = True message_slot.draw(draw) message_slot.advance() else: if (message_list): message_slot.set_message(message_list.pop()) if displaying_messages: frames_since_message = 0 else: frames_since_message += 1 if (frames_since_message >= frame_delay): draw_default(draw) current_time = time.time() time_delta = (1.0 / fps) - (current_time - prev_time) if (time_delta > 0.0): time.sleep(time_delta) prev_time = current_time # Copy the offscreen buffer to the screen. matrix.SetImage(image.im.id, 0, 0)
def __init__(self, version, qrECC, linkID,duration): self.linkID = linkID self.matrix = Adafruit_RGBmatrix(32,1) self.currentID = 0 self.version = version self.qrECC = qrECC self.qrSize = int(QR_DICTIONARIES.VERSION_SIZE[version]) self.dict = self.__selectDict__(qrECC) self.startTime = time() self.duration = duration
def __init__(self): self.font_width = 6 self.font_height = 10 self.max_char_width = 9 self.max_char_height = 2 self.matrix = Adafruit_RGBmatrix(32, 2) self.fontfile = os.path.join( os.path.dirname(os.path.abspath(__file__)), "fonts/{0}x{1}.bdf".format(self.font_width, self.font_height)) self.offset = [0, 0]
class Matrix: def __init__(self, height, chains): self.matrix = Adafruit_RGBmatrix(height, chains) self.MAX_Y = height self.MAX_X = height * chains self.obj_list = [] self.setBG(0x000000) def setBG(self, hex_color): self.BG = hex_color self.drawBG() def setBoard(self, board_num, rgb): self.fillRect(board_num*self.MAX_Y, 0, board_num*self.MAX_Y + self.MAX_Y, self.MAX_Y, rgb) def drawBG(self): self.matrix.Fill(self.BG) def clear(self): self.matrix.Clear() def setPixel(self, x, y, rgb): self.matrix.SetPixel(x, y, *rgb) def fillRect(self, x1, y1, x2, y2, rgb): for x in range(x1, x2): for y in range(y1, y2): self.setPixel(x, y, rgb) def drawPointList(self, plist, rgb): for point in plist: self.setPixel(point[0],point[1], rgb) def drawImage(self, file_name): image = Image.open(file_name) raw = image.load() for x in range(0,30): for y in range(0,63): rgb = raw[y, x] if rgb == (0,0,0): #If you wanted to make the background another color self.setPixel(y,x, (0,0,0)) else: self.setPixel(y, x, (rgb[0], rgb[1], rgb[2])) def refresh(self): self.drawBG() for obj in self.obj_list: obj.draw() def getMatrix(self): return self.matrix
def __init__(self): """ Initialise a new twitter display """ self.logger = logging.getLogger(self.__class__.__name__) self.logger.info("Initialising the Amp View") self.matrix = Adafruit_RGBmatrix(AmpView.PANEL_HEIGHT, AmpView.PANELS) self.__load_fonts() self.volume = "" self.source = "" self.timer = None self.model = None
def __init__(self): self.__initSerial() self.game_mode = self.MODE['ATTRACT'] self.matrix = Adafruit_RGBmatrix(32, 2, 3) self.image = Image.new("RGB", (96, 64)) self.draw = ImageDraw.Draw(self.image) font = ImageFont.truetype( "/usr/share/fonts/truetype/freefont/FreeSerif.ttf", 14) self.draw.text((20, 10), "LOADING", font=font, fill=(255, 60, 5)) self.draw.text((18, 30), "SKEEBALL", font=font, fill=(255, 60, 5)) self.matrix.Clear() self.matrix.SetImage(self.image.im.id, 0, 0) time.sleep(1)
def __init__(self): #self.__initSerial() self.game_mode = self.MODE['ATTRACT'] self.matrix = Adafruit_RGBmatrix(32,2,3) self.image = Image.new("RGB", (96, 64)) self.draw = ImageDraw.Draw(self.image) image = Image.open("imgs/penis.png") image.load() # Must do this before SetImage() calls self.matrix.SetImage(image.im.id,0,0) time.sleep(5) self.__start()
def __init__(self, version, qrECC, linkID, duration, speed): """Contructor""" self.linkID = linkID self.matrix = Adafruit_RGBmatrix(32, 1) self.currentID = 0 self.version = version self.versionLength = QR_DICTIONARIES.VERSION_SIZE[version] self.qrECC = qrECC self.qrSize = self.__selectDict__(qrECC) self.speed = speed self.startTime = time() self.duration = duration self.packetsSent = 0 self.bytesSent = 0 self.qrsSent = 0
class DriverAdaMatrix(DriverBase): # rows: height of the matrix, same as led-matrix example # chain: number of LEDMatrix panels, same as led-matrix example def __init__(self, rows=32, chain=1): super(DriverAdaMatrix, self).__init__(rows * 32 * chain) self._matrix = Adafruit_RGBmatrix(rows, chain) #Push new data to strand def update(self, data): self._matrix.SetBuffer(data) #Matrix supports between 2^1 and 2^11 levels of PWM #which translates to the total color bit-depth possible #A lower value will take up less CPU cycles def SetPWMBits(self, bits): if bits < 1 or bits > 11: raise ValueError("PWM level must be between 1 and 11") self._matrix.SetPWMBits(bits)
def __init__(self, interval=3): """ Constructor :type interval: int :param interval: Check interval, in seconds """ self.interval = interval self.channel_data = dict() self.histogram_data = list() self.showlight = False for i in chanlookup: self.channel_data[i] = dict() # Rows and chain length are both required parameters: if args.nolights is False: self.matrix = Adafruit_RGBmatrix(16, 1) # use a bitmap font if args.nolights is False: self.font = ImageFont.load("rpi-rgb-led-matrix/fonts/4x6.pil") if args.nolights is False: self.font2 = ImageFont.load("rpi-rgb-led-matrix/fonts/5x7.pil") thread = threading.Thread(target=self.run, args=()) thread.daemon = True # Daemonize thread thread.start() # Start the execution
class RGB_Matrix(Device): """ Handles output to the Adafruit RGB Matrix """ def __init__(self): self.capabilities(MATRIX_WIDTH, MATRIX_HEIGHT, mode="RGB") # Use Adafruit's RGB Matrix class from rgbmatrix import Adafruit_RGBmatrix self._matrix = Adafruit_RGBmatrix(32, 1) def display(self): self._matrix.SetImage(self.image.im.id) def clear(self): self._matrix.Clear() self.image = Image.new(self.mode, self.size)
def main(): if len(sys.argv) != 2: sys.exit('usage: {} <src_dir>'.format(sys.argv[0])) if not os.path.isdir(sys.argv[1]): sys.exit('{} is not a directory'.format(sys.argv[1])) dir_src = os.path.normpath(sys.argv[1]) images = sorted(list_files_with_ext(dir_src, JPEG)) matrix = Adafruit_RGBmatrix(MATRIX_SIZE, MATRIX_CHAIN) try: while True: for image in images: im = Image.open(image) im.load() matrix.SetImage(im.im.id, 0, 0) time.sleep(SLEEP) except KeyboardInterrupt: pass matrix.Clear()
class Printer: def __init__(self): self.font_width = 6 self.font_height = 10 self.max_char_width = 9 self.max_char_height = 2 self.matrix = Adafruit_RGBmatrix(32, 2) self.fontfile = os.path.join( os.path.dirname(os.path.abspath(__file__)), "fonts/{0}x{1}.bdf".format(self.font_width, self.font_height)) self.offset = [0, 0] def offset_x(self): return self.offset[0] * self.font_width def offset_y(self): return self.offset[1] * self.font_height def draw_char(self, char): # If return, set offset to new line try: test = ord(char) == 10 except TypeError: test = False if test: self.offset[0] = 0 self.offset[1] += 1 else: self.matrix.DrawText(self.fontfile, self.offset_x(), self.offset_y(), 0xFF, 0xFF, 0xFF, char) self.offset[0] += 1 if self.offset[0] > self.max_char_width: self.offset[0] = 0 self.offset[1] += 1 if self.offset[1] > self.max_char_height: self.offset[1] = 0 self.matrix.Clear()
def main(argv=[]): logging.getLogger().setLevel( logging.DEBUG if DEBUG_DISPLAY else logging.INFO) logging.info("running") def quit_handler(signal, frame): logging.info("Interrupted") a.finish() signal.signal(signal.SIGINT, quit_handler) logging.debug("Creating matrix") matrix = Adafruit_RGBmatrix(LED_MATRIX_ROWS, 1) logging.debug("Starting renderer") a = LedApp(matrix, None) while True: try: a.refresh() except Exception as e: logging.exception("Top level exception") a.finish() a.finish()
def alloc_matrix(self): self.matrix = Adafruit_RGBmatrix(32, 2)
class RGBMatrixDisplay: def __init__(self): self.curFileName = "" self.matrix = None self.alloc_matrix() self.font = Font() self.font.setColor(1,255,1) self.num = 0 thread.start_new_thread(self.keythread,()) def alloc_matrix(self): self.matrix = Adafruit_RGBmatrix(32, 2) def free_matrix(self): self.matrix.Clear() self.matrix = None def checkExtension(self, filename, extension): file_len = len(filename) ext_len = len(extension) + 1 if str.upper(filename[file_len - ext_len:]) == "." + str.upper(extension): return True else: return False def keythread(self): serv = MSGserver("localhost", 5000) serv.listen() self.num = 0 while True: data = serv.recv() if data == "start": self.num = 1 elif data == "key": self.num +=1 elif data == "end": self.num = 0 elif data == "err": sys.exit() def show(self): global playFileName self.curFileName = playFileName while True: if self.checkExtension(self.curFileName,"mp4") or self.checkExtension(self.curFileName,"avi"): cap = cv2.VideoCapture(self.curFileName) total_frame = cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT) count = 1 while (True): if self.curFileName != playFileName: self.curFileName = str(playFileName) break _, frame = cap.read() cv2.waitKey(24) pil_im = Image.fromarray(frame) self.matrix.SetImage(pil_im.im.id, 0, 0) # draw combo combo = self.num if combo >0: s = str(combo) sl = len(s) x_start_pos =32-int((sl*6)/2.0) for index,n in enumerate(s): self.font.drawNumber(self.matrix,x_start_pos+(index*6),13,int(n)) else: pass count += 1 if count >= total_frame - 1: cap.set(1, 1) count = 1 cap.release()
from __future__ import unicode_literals import Image import ImageDraw import time import ImageFont from rgbmatrix import Adafruit_RGBmatrix import ImageOps import pickle with open("emojiemotionlist.txt", "rb") as fp: # Unpickling emojilist = pickle.load(fp) print(len(emojilist)) # print(emojilist[0:10]) matrix = Adafruit_RGBmatrix(32, 4) num = len(emojilist) rep = 4 im = Image.new("RGB", (32 * num * rep, 32)) size = 32, 32 for n in range(0, rep * num, 1): print(emojilist[n % num]) emoji = Image.open(emojilist[n % num]) emoji.thumbnail(size, Image.ANTIALIAS) emoji.load() # Must do this before SetImage() calls im.paste(emoji, (n * 32 + 1, 0)) print(im.size[0]) for n in range(128, -im.size[0], -1): # Scroll R to L
#!/usr/bin/python import time from rgbmatrix import Adafruit_RGBmatrix matrix = Adafruit_RGBmatrix(32, 1) matrix.Clear() def spiral(n): center = (n - 1) / 2 position = center * (1 + 1j) direction = 1 arm_length = 1 count = 0 while True: for _ in range(2): for _ in range(2): for _ in range(arm_length): coords = int(position.real), int(position.imag) yield coords position += direction count += 1 if count == n * n: return direction *= 1j arm_length += 1
# These functions have an immediate effect on the display; no special # refresh operation needed. # Requires rgbmatrix.so present in the same directory. import numpy, pprint, sys, Queue from assets import loadLetters from charFlipper import flip from wordcontroller import chartopix from locationservices import displayAt import string import time from rgbmatrix import Adafruit_RGBmatrix from shapes import * # Rows and chain length are both required parameters: matrix = Adafruit_RGBmatrix(32, 1) time.sleep(2.0) matrix.Clear() #shapes- rect test square_fill = rect(5, 7, 0) square_empt = rect(5, 7, 1) #for row in square_empt: # for val in row: # print '{:4}'.format(val) # print test_screen0 = displayAt(0, 0, square_fill) test_screen1 = displayAt(0, 7, square_empt) for i in range(0, 32): for j in range(0, 32): if test_screen0[i][j] == 1:
import time import bitcoinAuth import pyqrcode import socket, httplib from bitcoinrpc import AuthServiceProxy, JSONRPCException from rgbmatrix import Adafruit_RGBmatrix matrix = Adafruit_RGBmatrix(32, 1) matrix.Clear() rpc_connection = AuthServiceProxy("http://%s:%[email protected]:8332"%(bitcoinAuth.USER,bitcoinAuth.PW)) print "Loading 1st bitcoin address..." #addr = rpc_connection.getnewaddress() addr = 'L45S4EjxBtD9He53GxqCvVPjk7NpU83PYVJgUVM7xqbLRVju9rTc' code = pyqrcode.create(addr, error='L', version=3) t = code.text(1) print addr print t row = 31 col = 0 for i in t: if i != '\n': matrix.SetPixel(row, col, 255-int(i)*255, 255-int(i)*255, 255-int(i)*255) col += 1 else: row -= 1
# string on each line can then be edited for brevity if desired. stops = [ ('sf-muni', 'N', '7318', 'Inbound'), ('sf-muni', '24', '4330', 'Castro'), ('sf-muni', '24', '4331', 'Divis'), # ('sf-muni', '22', '5018', 'Mission'), ] maxPredictions = 3 # NextBus shows up to 5; limit to 3 for simpler display minTime = 0 # Drop predictions below this threshold (minutes) shortTime = 5 # Times less than this are displayed in red midTime = 10 # Times less than this are displayed yellow width = 32 # Matrix size (pixels) -- change for different matrix height = 16 # types (incl. tiling). Other code may need tweaks. matrix = Adafruit_RGBmatrix(16, 1) # rows, chain length fps = 12 # Scrolling speed (ish) routeColor = (255, 255, 255) # Color for route labels (usu. numbers) descColor = (110, 110, 110) # " for route direction/description longTimeColor = (0, 255, 0) # Ample arrival time = green midTimeColor = (255, 255, 0) # Medium arrival time = yellow shortTimeColor = (255, 0, 0) # Short arrival time = red minsColor = (110, 110, 110) # Commans and 'minutes' labels noTimesColor = (0, 0, 255) # No predictions = blue # TrueType fonts are a bit too much for the Pi to handle -- slow updates and # it's hard to get them looking good at small sizes. A small bitmap version # of Helvetica Regular taken from X11R6 standard distribution works well: font = ImageFont.load( os.path.dirname(os.path.realpath(__file__)) + '/helvR08.pil')
#!/usr/bin/python # Simple RGBMatrix example, using only Clear(), Fill() and SetPixel(). # These functions have an immediate effect on the display; no special # refresh operation needed. # Requires rgbmatrix.so present in the same directory. import Image import ImageDraw import time from rgbmatrix import Adafruit_RGBmatrix # Rows and chain length are both required parameters: matrix = Adafruit_RGBmatrix(32, 2) # Flash screen red, green, blue (packed color values) matrix.Fill(0xFF0000) time.sleep(1.0) matrix.Fill(0x00FF00) time.sleep(1.0) matrix.Fill(0x0000FF) time.sleep(1.0) # Show RGB test pattern (separate R, G, B color values) for b in range(16): for g in range(8): for r in range(8): matrix.SetPixel((b / 4) * 8 + g, (b & 3) * 8 + r, (r * 0b001001001) / 2, (g * 0b001001001) / 2, b * 0b00010001)
#!/usr/bin/python import Image import ImageDraw import signal import sys import time from rgbmatrix import Adafruit_RGBmatrix matrix = Adafruit_RGBmatrix(32, 1) def signal_handler(signal, frame): matrix.Clear() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) def draw_animated(filename): image = Image.open(filename) duration = image.info.get("duration", 30) / 1000.0 while True: image.load() # Must do this before SetImage() calls matrix.SetImage(image.im.id, 0, 0) time.sleep(duration) try: image.seek(image.tell() + 1) except: matrix.Clear()
#!/usr/bin/python # Simple RGBMatrix example, using only Clear(), Fill() and SetPixel(). # These functions have an immediate effect on the display; no special # refresh operation needed. # Requires rgbmatrix.so present in the same directory. import time from rgbmatrix import Adafruit_RGBmatrix # Rows and chain length are both required parameters: matrix = Adafruit_RGBmatrix(32,2,3) # Flash screen red, green, blue (packed color values) matrix.Fill(0xFF0000) time.sleep(1.0) matrix.Fill(0x00FF00) time.sleep(1.0) matrix.Fill(0x0000FF) time.sleep(1.0) matrix.Fill(0x000000) # Show RGB test pattern (separate R, G, B color values) matrix.SetPixel(0,0,255,0,0) time.sleep(1) matrix.SetPixel(10,10,0,255,0) time.sleep(1) matrix.SetPixel(40,40,0,0,255) time.sleep(1) matrix.SetPixel(60,60,255,255,0) time.sleep(1)
emulation = False if (emulation): from display import display as Adafruit_RBGmatrix else: from rgbmatrix import Adafruit_RGBmatrix import time import Image matrix = Adafruit_RGBmatrix(32, 1) def run(): matrix.Clear() animation = "fireworks" for i in range(0, 5): for x in range(0, 42): image = Image.open(str(x) + ".png") image.load() matrix.SetImage(image.im.id, 0, 0) time.sleep(0.05) def kill(): matrix.Clear() if (emulation): matrix.start(run, kill) else: run()