def led_matrix_options(args): options = RGBMatrixOptions() if args.led_gpio_mapping != None: options.hardware_mapping = args.led_gpio_mapping options.rows = args.led_rows options.cols = args.led_cols options.chain_length = args.led_chain options.parallel = args.led_parallel options.row_address_type = args.led_row_addr_type options.multiplexing = args.led_multiplexing options.pwm_bits = args.led_pwm_bits options.brightness = args.led_brightness options.pwm_lsb_nanoseconds = args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = args.led_rgb_sequence if args.led_show_refresh: options.show_refresh_rate = 1 if args.led_slowdown_gpio != None: options.gpio_slowdown = args.led_slowdown_gpio if args.led_no_hardware_pulse: options.disable_hardware_pulsing = True return options
def led_matrix_options(args): options = RGBMatrixOptions() if args.led_gpio_mapping != None: options.hardware_mapping = args.led_gpio_mapping options.rows = args.led_rows options.cols = args.led_cols options.chain_length = args.led_chain options.parallel = args.led_parallel options.row_address_type = args.led_row_addr_type options.multiplexing = args.led_multiplexing options.pwm_bits = args.led_pwm_bits options.brightness = args.led_brightness options.pwm_lsb_nanoseconds = args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = args.led_rgb_sequence try: options.pixel_mapper_config = args.led_pixel_mapper except AttributeError: debug.warning("Your compiled RGB Matrix Library is out of date.") debug.warning("The --led-pixel-mapper argument will not work until it is updated.") if args.led_show_refresh: options.show_refresh_rate = 1 if args.led_slowdown_gpio != None: options.gpio_slowdown = args.led_slowdown_gpio if args.led_no_hardware_pulse: options.disable_hardware_pulsing = True return options
def process(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping != None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = self.args.led_rows options.chain_length = self.args.led_chain options.parallel = self.args.led_parallel options.pwm_bits = self.args.led_pwm_bits options.brightness = self.args.led_brightness options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds if self.args.led_show_refresh: options.show_refresh_rate = 1 if self.args.led_slowdown_gpio != None: options.gpio_slowdown = self.args.led_slowdown_gpio if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options = options) try: # Start loop print("Press CTRL-C to stop sample") self.run() except KeyboardInterrupt: print("Exiting\n") sys.exit(0) return True
def canvas_init(self, arg): options = RGBMatrixOptions() options.rows = arg.led_rows fontsize_book = int(arg.font_main[0]) if arg.font_main else 16 fontsize_bold = int(arg.font_bold[0]) if arg.font_bold else 16 self.FELD_LOOP = [ "man", "design", "branding", "advertising", "typography", "photography", "illustration", "editorial", "video", "print", "web" ] self.ANIMATION_TIME = arg.animation_time[ 0] if arg.animation_time else 10 self.YSHIFT = arg.yshift[0] if arg.yshift else 5 self.PREFIX = arg.prefx[0] if arg.prefx else "Feld" self.SUFFIX = arg.suffx[0] if arg.suffx else "" self.MAIN_COLOR = graphics.Color(255, 255, 255) self.MARGIN_LEFT = arg.margin_left[0] if arg.margin_left else 0 self.MARGIN_TOP = arg.margin_top[0] if arg.margin_top else ( options.rows + fontsize_bold) / 2 self.FONT_MAIN = graphics.Font() self.FONT_MAIN.LoadFont("libs/myfont/weights/font_" + str(fontsize_book) + "_book.bdf") self.FONT_BOLD = graphics.Font() self.FONT_BOLD.LoadFont("libs/myfont/weights/font_" + str(fontsize_bold) + "_bold.bdf") self.SPACE_AFTER_PREFIX = arg.space_after_prefix[ 0] if arg.space_after_prefix else 0 self.SPACE_BEFORE_SUFFIX = arg.space_before_suffix[ 0] if arg.space_before_suffix else 0 if arg.led_gpio_mapping != None: options.hardware_mapping = arg.led_gpio_mapping options.chain_length = arg.led_chain options.parallel = arg.led_parallel options.pwm_bits = arg.led_pwm_bits options.brightness = arg.led_brightness options.pwm_lsb_nanoseconds = arg.led_pwm_lsb_nanoseconds options.led_rgb_sequence = arg.led_rgb_sequence if arg.led_show_refresh: options.show_refresh_rate = 1 if arg.led_slowdown_gpio != None: options.gpio_slowdown = arg.led_slowdown_gpio if arg.led_no_hardware_pulse: options.disable_hardware_pulsing = True return RGBMatrix(options=options)
def __init__(self, rows, cols, refresh_rate=20): self.rows = rows self.cols = cols self.refresh_rate = refresh_rate options = RGBMatrixOptions() options.rows = rows options.cols = cols options.hardware_mapping = 'adafruit-hat' self.options = options self.matrix = RGBMatrix(options=options) self.font = create_font() self.widths = widths( self.font, '$!@#%^*()[]0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-=+_. ' ) self.frame = self.matrix.CreateFrameCanvas()
def __init__(self, panel_rows, panel_columns, num_horiz_panels, num_vert_panels): self.total_rows = panel_rows * num_vert_panels self.total_columns = panel_columns * num_horiz_panels options = RGBMatrixOptions() options.rows = matrix_rows options.cols = matrix_columns options.chain_length = num_horiz_panels options.parallel = num_vert_panels options.hardware_mapping = 'regular' #options.gpio_slowdown = 2 self.matrix = RGBMatrix(options=options) self.background = None self.icons = [] self.screen = Image.new("RGBA", (self.total_columns, self.total_rows))
def getOptions(self): options = RGBMatrixOptions() options.hardware_mapping = "regular" options.rows = 16 options.cols = 32 options.chain_length = 1 options.parallel = 1 options.row_address_type = 0 options.multiplexing = 0 options.pwm_bits = 11 options.brightness = 50 options.pwm_lsb_nanoseconds = 130 options.led_rgb_sequence = "RGB" options.show_refresh_rate = 0 options.gpio_slowdown = 4 options.disable_hardware_pulsing = False options.scan_mode = 1 return options
def process(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping != None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = self.args.led_rows options.cols = self.args.led_cols options.chain_length = self.args.led_chain options.parallel = self.args.led_parallel options.row_address_type = self.args.led_row_addr_type options.multiplexing = self.args.led_multiplexing options.pwm_bits = self.args.led_pwm_bits options.brightness = self.args.led_brightness options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = self.args.led_rgb_sequence options.pixel_mapper_config = self.args.led_pixel_mapper if self.args.led_show_refresh: options.show_refresh_rate = 1 if self.args.led_slowdown_gpio != None: options.gpio_slowdown = self.args.led_slowdown_gpio if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options=options) self.canvas = self.matrix.CreateFrameCanvas() clock_mode = self.args.clock_color try: # Start loop print("Press CTRL-C to stop sample") self.run(clock_mode) except KeyboardInterrupt: print("Exiting\n") sys.exit(0) return True
def rgbmatrix_options(): options = RGBMatrixOptions() options.multiplexing = 0 options.row_address_type = 0 options.brightness = 100 options.rows = led_panel_height options.cols = led_panel_width options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'regular' options.inverse_colors = False options.led_rgb_sequence = "RGB" options.gpio_slowdown = 3 options.pwm_lsb_nanoseconds = 150 options.show_refresh_rate = 0 options.disable_hardware_pulsing = True options.scan_mode = 0 options.pwm_bits = 11 options.daemon = 0 options.drop_privileges = 0 return options
def __init__(self): # Configuration for the matrix options = RGBMatrixOptions() options.rows = 32 options.cols = 32 options.chain_length = 1 options.parallel = 1 options.gpio_slowdown = 5 options.hardware_mapping = 'adafruit-hat' # Enter in the hardware configurations self.matrix = RGBMatrix(options=options) # Specifications for Font style of text self.font = graphics.Font() self.font.LoadFont("rpi-rgb-led-matrix/fonts/4x6.bdf") self.textColor = graphics.Color(100, 100, 100) self.fontWidth = 4 self.fontHeight = 6 self.canvas = self.matrix.CreateFrameCanvas()
def rgbmatrix_options_factory(config): """Build RGBMatrix options object.""" options = RGBMatrixOptions() if config['led-gpio-mapping'] is not None: options.hardware_mapping = config['led-gpio-mapping'] options.rows = config['led-rows'] options.cols = config['led-cols'] options.chain_length = config['led-chain'] options.parallel = config['led-parallel'] options.pwm_bits = config['led-pwm-bits'] options.brightness = config['led-brightness'] options.pwm_lsb_nanoseconds = config['led-pwm-lsb-nanoseconds'] if config['led-show-refresh']: options.show_refresh_rate = 1 if config['led-slowdown-gpio'] is not None: options.gpio_slowdown = config['led-slowdown-gpio'] if config['led-no-hardware-pulse']: options.disable_hardware_pulsing = True # mapper not yet available in lib # options.led_pixel_mapper = config['led-pixel-mapper'] return options
def matrix_options(): # Put this include within the function so that the rest of this file can # be imported by ledweb, which doesn't necessarily have `rgbmatrix` # available in its environment. from rgbmatrix import RGBMatrixOptions options = RGBMatrixOptions() options.rows = 32 options.cols = 64 options.chain_length = 1 options.parallel = 1 # Use 'adafruit-hat' if you haven't soldered GPIO pins 4 and 18 together # (see https://github.com/hzeller/rpi-rgb-led-matrix#switch-the-pinout). options.hardware_mapping = 'adafruit-hat-pwm' # Newer Raspberry PIs put out data too quickly, which causes flickering. # This slows them down. options.gpio_slowdown = 2 return options
def rgbmatrix_options(): options = RGBMatrixOptions() options.multiplexing = 6 options.row_address_type = 0 options.brightness = 80 options.rows = number_of_rows_per_panel options.cols = number_of_columns_per_panel options.chain_length = number_of_panels options.parallel = parallel options.hardware_mapping = 'regular' options.inverse_colors = False options.led_rgb_sequence = "BGR" options.gpio_slowdown = 1 options.pwm_lsb_nanoseconds = 130 options.show_refresh_rate = 0 options.disable_hardware_pulsing = False options.scan_mode = 0 options.pwm_bits = 11 options.daemon = 0 options.drop_privileges = 0 return options
def rgbmatrix_options_factory(config): """Build RGBMatrix options object.""" options = RGBMatrixOptions() if config["led-gpio-mapping"] is not None: options.hardware_mapping = config["led-gpio-mapping"] options.rows = config["led-rows"] options.cols = config["led-cols"] options.chain_length = config["led-chain"] options.parallel = config["led-parallel"] options.pwm_bits = config["led-pwm-bits"] options.brightness = config["led-brightness"] options.pwm_lsb_nanoseconds = config["led-pwm-lsb-nanoseconds"] if config["led-show-refresh"]: options.show_refresh_rate = 1 if config["led-slowdown-gpio"] is not None: options.gpio_slowdown = config["led-slowdown-gpio"] if config["led-no-hardware-pulse"]: options.disable_hardware_pulsing = True if config["led-pixel-mapper"]: options.pixel_mapper_config = config["led-pixel-mapper"] return options
def process(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping != None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = self.args.led_rows options.cols = self.args.led_cols options.chain_length = self.args.led_chain options.parallel = self.args.led_parallel options.row_address_type = self.args.led_row_addr_type options.multiplexing = self.args.led_multiplexing options.pwm_bits = self.args.led_pwm_bits options.brightness = self.args.led_brightness options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = self.args.led_rgb_sequence #<<<<<<< HEAD #======= #options.pixel_mapper_config = self.args.led_pixel_mapper #>>>>>>> d25e9b6a2d0fa1879927ed18780b27e8464352f7 if self.args.led_show_refresh: options.show_refresh_rate = 1 if self.args.led_slowdown_gpio != None: options.gpio_slowdown = self.args.led_slowdown_gpio if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options=options) try: # Start loop print("Press CTRL-C to stop sample") self.run() except KeyboardInterrupt: print("Exiting\n") sys.exit(0) return True
def process(self): options = RGBMatrixOptions() if self.args['led_gpio_mapping'] is not None: options.hardware_mapping = self.args['led_gpio_mapping'] options.rows = self.args['led_rows'] options.cols = self.args['led_cols'] options.chain_length = self.args['led_chain'] options.parallel = self.args['led_parallel'] options.row_address_type = self.args['led_row_addr_type'] options.multiplexing = self.args['led_multiplexing'] options.pwm_bits = self.args['led_pwm_bits'] options.brightness = self.args['led_brightness'] options.pwm_lsb_nanoseconds = self.args['led_pwm_lsb_nanoseconds'] options.led_rgb_sequence = self.args['led_rgb_sequence'] options.pixel_mapper_config = self.args['led_pixel_mapper'] options.panel_type = self.args['led_panel_type'] if self.args['led_show_refresh']: options.show_refresh_rate = 1 if self.args['led_slowdown_gpio'] is not None: options.gpio_slowdown = self.args['led_slowdown_gpio'] if self.args['led_no_hardware_pulse']: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options=options) try: print('Press CTRL-C to stops') self.run() except KeyboardInterrupt: print('Exiting\n') sys.exit(0) return True
def __init__(self, LEDFormat): logging.info('Initialising LEDMatrix') options = RGBMatrixOptions() options.hardware_mapping = LEDFormat['matrixDriver'] options.rows = LEDFormat['matrixRows'] options.cols = LEDFormat['matrixCols'] options.chain_length = LEDFormat['matrixCount'] options.pixel_mapper_config = LEDFormat['matrixMapper'] options.row_address_type = 0 options.multiplexing = 0 options.pwm_bits = 11 options.brightness = 100 options.pwm_lsb_nanoseconds = 130 options.led_rgb_sequence = "RGB" options.show_refresh_rate = 0 self.__MatrixID = RGBMatrix(options = options) self.__MatrixID.Clear() xsize = self.__MatrixID.width ysize = self.__MatrixID.height self.__LEDXSize = xsize self.__LEDYSize = ysize self.__LEDXMax = xsize - 1 self.__LEDYMax = ysize - 1 self.__DrawOnMatrix = True self.__MatrixCanvas = Canvas((self.__LEDXSize, self.__LEDYSize)) self.__FadeMatrixCanvas = Canvas((self.__LEDXSize, self.__LEDYSize)) self.__MatrixBuffer = self.__MatrixID.CreateFrameCanvas()
def process(self): self.args = self.parser.parse_args() options = RGBMatrixOptions() if self.args.led_gpio_mapping != None: options.hardware_mapping = self.args.led_gpio_mapping options.rows = NUM_ROWS options.cols = NUM_COLS options.chain_length = CHAIN_LEN options.parallel = self.args.led_parallel options.row_address_type = self.args.led_row_addr_type options.multiplexing = self.args.led_multiplexing options.pwm_bits = self.args.led_pwm_bits options.brightness = BRIGHTNESS options.pwm_lsb_nanoseconds = self.args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = self.args.led_rgb_sequence options.pixel_mapper_config = self.args.led_pixel_mapper # options.panel_type = self.args.led_panel_type if self.args.led_show_refresh: options.show_refresh_rate = 1 options.gpio_slowdown = GPIO_SLOWDOWN if self.args.led_no_hardware_pulse: options.disable_hardware_pulsing = True self.matrix = RGBMatrix(options=options) try: # Start loop print("Press CTRL-C to stop sample") self.run() except KeyboardInterrupt: print("Exiting\n") sys.exit(0) return True
def __init__(self, gamepad): self.gamepad = gamepad self.player = SpaceShip() self.num_rocks = 10 self.rocks = [] for i in range(self.num_rocks): self.rocks.append(Rock()) options = RGBMatrixOptions() options.hardware_mapping = "regular" options.rows = 64 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.row_address_type = 0 options.multiplexing = 0 options.pwm_bits = 11 options.brightness = 100 options.pwm_lsb_nanoseconds = 130 #options.led_rgb_sequence = "RGB" options.pixel_mapper_config = "" self.matrix = RGBMatrix(options = options)
def __init__(self, rows, chain_length, brightness): """Initialize a LED matrix. Args: rows: The numberof matrix rows (usually 32 or 64). chain_length: The number of daisy-chained panels. brightness: LED brightness (0-100). """ # LED control options options = RGBMatrixOptions() options.rows = rows options.chain_length = chain_length options.parallel = 1 options.hardware_mapping = 'adafruit-hat' options.brightness = brightness self.matrix = RGBMatrix(options=options) self.img = Image.new('RGB', (rows * chain_length, rows), (0, 0, 0)) self.stop_event = threading.Event() self.update_event = threading.Event() threading.Thread.__init__(self)
def init_leds(): options = RGBMatrixOptions() options.hardware_mapping = 'regular' options.rows = 32 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.row_address_type = 0 options.multiplexing = 0 options.brightness = 85 options.pwm_bits = 8 options.pwm_lsb_nanoseconds = 130 options.led_rgb_sequence = 'RGB' options.pixel_mapper_config = '' options.panel_type = '' options.limit_refresh_rate_hz = 0 # no fps limit decreases the cpu usage options.show_refresh_rate = 0 options.gpio_slowdown = 4 options.disable_hardware_pulsing = False options.drop_privileges = False return RGBMatrix(options=options)
def rgbmatrix_options(): options = RGBMatrixOptions() options.multiplexing = 1 options.row_address_type = 0 options.brightness = 60 options.rows = 64 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'regular' options.inverse_colors = False options.led_rgb_sequence = "GBR" options.gpio_slowdown = 4 options.pwm_lsb_nanoseconds = 50 options.show_refresh_rate = 1 options.disable_hardware_pulsing = False options.scan_mode = 1 options.pwm_bits = 11 # options.daemon = 0 # options.drop_privileges = 0 # options.pixel_mapper_config = "U-mapper;Rotate:90" options.pixel_mapper_config = "Rotate:90" return RGBMatrix(options=options)
def led_matrix_options(args): options = RGBMatrixOptions() if args.led_gpio_mapping != None: options.hardware_mapping = args.led_gpio_mapping options.rows = args.led_rows options.chain_length = args.led_chain options.parallel = args.led_parallel options.pwm_bits = args.led_pwm_bits options.brightness = args.led_brightness options.pwm_lsb_nanoseconds = args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = args.led_rgb_sequence if args.led_show_refresh: options.show_refresh_rate = 1 if args.led_slowdown_gpio != None: options.gpio_slowdown = args.led_slowdown_gpio if args.led_no_hardware_pulse: options.disable_hardware_pulsing = True return options
def led_matrix_options(args): options = RGBMatrixOptions() if args.led_gpio_mapping != None: options.hardware_mapping = args.led_gpio_mapping options.rows = args.led_rows options.cols = args.led_cols options.chain_length = args.led_chain options.parallel = args.led_parallel options.row_address_type = args.led_row_addr_type options.multiplexing = args.led_multiplexing options.pwm_bits = args.led_pwm_bits options.brightness = args.led_brightness options.pwm_lsb_nanoseconds = args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = args.led_rgb_sequence options.panel_type = args.led_panel_type options.limit_refresh_rate_hz = args.led_limit_refresh try: options.pixel_mapper_config = args.led_pixel_mapper except AttributeError: debug.warning("Your compiled RGB Matrix Library is out of date.") debug.warning( "The --led-pixel-mapper argument will not work until it is updated." ) if args.led_show_refresh: options.show_refresh_rate = 1 if args.led_slowdown_gpio != None: options.gpio_slowdown = args.led_slowdown_gpio if args.led_no_hardware_pulse: options.disable_hardware_pulsing = True return options
from rgbmatrix import RGBMatrix, RGBMatrixOptions from PIL import Image if len(sys.argv) < 2: sys.exit("Require an image argument") else: image_file = sys.argv[1] image = Image.open(image_file) # Configuration for the matrix options = RGBMatrixOptions() options.rows = 32 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'regular' # If you have an Adafruit HAT: 'adafruit-hat' matrix = RGBMatrix(options = options) # Make image fit our screen. image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS) matrix.SetImage(image.convert('RGB')) try: print("Press CTRL-C to stop.") while True: time.sleep(100) except KeyboardInterrupt: sys.exit(0)
def to_matrix(minutes): # How fast for testing sleep_i = 1 # matrix options set here options = RGBMatrixOptions() options.rows = 32 options.chain_length = 2 options.hardware_mapping = 'adafruit-hat' options.parallel = 1 # orient_image arguments here mat_x = options.chain_length * options.rows mat_y = options.rows char_w = 8 char_h = 13 num_chars = 8 lines= 1 O = orient_image(mat_x, mat_y, char_w ,char_h, num_chars,lines) matrix = RGBMatrix(options = options) image = Image.new("RGB", (64, 32)) draw = ImageDraw.Draw(image) matrix.Clear() # image files found in respective directories png = PNG_8x13 # create the countdown timer here T = timer(minutes) try: # First for loop takes the initial list of lists and starts itering through print 'countdown timer started' while 1: for i in T: # Second for loop takes each individual list itme and iters through, printing to the matrix # this updates later according to the offset x_matrix_pos = O[0] # with a single row of chars this wont change y_matrix_pos = O[1] # this is how far away the next char will print from the previous x_matrix_offset = O[2] print i for j in i: #print "i ", i,"\nj ", j image = Image.open("%s" % png[j]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) x_matrix_pos += x_matrix_offset sleep(sleep_i) # display zero status at the end of the timer print "countdown timer finished" while 1: # last list item in timer zero_status = T[-1] x_matrix_pos = O[0] y_matrix_pos = O[1] x_matrix_offset = O[2] for i in zero_status: image = Image.open("%s" % png[i]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) x_matrix_pos += x_matrix_offset except Exception as e: matrix.Clear() print e except KeyboardInterrupt: matrix.Clear() print 'sorry to see you go'
from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics from time import sleep import random import colorsys mode = 0 maxdrops = 500 options = RGBMatrixOptions() options.rows = 32 options.chain_length = 4 options.disable_hardware_pulsing = 0 options.gpio_slowdown = 1 options.brightness = 100 options.pwm_bits = 11 options.hardware_mapping = "adafruit-hat" mode = 0 class Drop: def __init__(self): global mode self.x = 0 self.y = random.randint(0, 31) self.r = self.b = self.g = 0 self.generateColor() self.speed = 1 + (random.random() * 4) self.strength = random.randint(40, 100) / 100.0 def generateColor(self):
def setup(self): """ Returns False on success, True on error """ parser = argparse.ArgumentParser() # RGB matrix standards parser.add_argument( "-r", "--led-rows", action="store", help="Display rows. 32 for 32x32, 64 for 64x64. Default: 64", default=64, type=int, ) parser.add_argument( "--led-cols", action="store", help="Panel columns. Typically 32 or 64. (Default: 64)", default=64, type=int, ) parser.add_argument( "-c", "--led-chain", action="store", help="Daisy-chained boards. Default: 6.", default=6, type=int, ) parser.add_argument( "-P", "--led-parallel", action="store", help="For Plus-models or RPi2: parallel chains. 1..3. Default: 1", default=1, type=int, ) parser.add_argument( "-p", "--led-pwm-bits", action="store", help="Bits used for PWM. Something between 1..11. Default: 11", default=11, type=int, ) parser.add_argument( "-b", "--led-brightness", action="store", help="Sets brightness level. Default: 100. Range: 1..100", default=100, type=int, ) parser.add_argument( "-m", "--led-gpio-mapping", help="Hardware Mapping: regular, adafruit-hat, adafruit-hat-pwm", choices=[ "regular", "regular-pi1", "adafruit-hat", "adafruit-hat-pwm" ], type=str, ) parser.add_argument( "--led-scan-mode", action="store", help= "Progressive or interlaced scan. 0 Progressive, 1 Interlaced (default)", default=1, choices=range(2), type=int, ) parser.add_argument( "--led-pwm-lsb-nanoseconds", action="store", help="Base time-unit for the on-time in the lowest " "significant bit in nanoseconds. Default: 130", default=130, type=int, ) parser.add_argument( "--led-show-refresh", action="store_true", help="Shows the current refresh rate of the LED panel", ) parser.add_argument( "--led-slowdown-gpio", action="store", help="Slow down writing to GPIO. Range: 0..4. Default: 3", default=4, # For Pi 4 w/6 matrices type=int, ) parser.add_argument( "--led-no-hardware-pulse", action="store", help="Don't use hardware pin-pulse generation", ) parser.add_argument( "--led-rgb-sequence", action="store", help="Switch if your matrix has led colors swapped. Default: RGB", default="RGB", type=str, ) parser.add_argument( "--led-pixel-mapper", action="store", help='Apply pixel mappers. e.g "Rotate:90"', default="", type=str, ) parser.add_argument( "--led-row-addr-type", action="store", help="0 = default; 1=AB-addressed panels; 2=row direct; " "3=ABC-addressed panels; 4 = ABC Shift + DE direct", default=0, type=int, choices=[0, 1, 2, 3, 4], ) parser.add_argument( "--led-multiplexing", action="store", help="Multiplexing type: 0=direct; 1=strip; 2=checker; 3=spiral; " "4=ZStripe; 5=ZnMirrorZStripe; 6=coreman; 7=Kaler2Scan; " "8=ZStripeUneven... (Default: 0)", default=0, type=int, ) parser.add_argument( "--led-panel-type", action="store", help="Needed to initialize special panels. Supported: 'FM6126A'", default="", type=str, ) parser.add_argument( "--led-no-drop-privs", dest="drop_privileges", help= "Don't drop privileges from 'root' after initializing the hardware.", action="store_false", ) # Extra args unique to this program parser.add_argument( "-i", action="store", help="Image filename for texture map. Default: maps/earth.jpg", default="maps/earth.jpg", type=str, ) parser.add_argument( "-v", dest="pointy", help="Orient cube with vertices at top & bottom.", action="store_true", ) parser.add_argument( "-s", action="store", help="Spin time in seconds/revolution. Default: 10.0", default=10.0, type=float, ) parser.add_argument( "-a", action="store", help="Antialiasing samples/axis. Default: 1", default=1, type=int, ) parser.add_argument( "-t", action="store", help="Run time in seconds. Default: run indefinitely", default=-1.0, type=float, ) parser.add_argument( "-f", action="store", help="Fade in/out time in seconds. Default: 0.0", default=0.0, type=float, ) parser.add_argument( "-e", action="store", help="Edge-to-edge measure of matrix.", default=1.0, type=float, ) parser.add_argument( "-E", action="store", help="Edge-to-edge measure of opposite cube faces.", default=1.0, type=float, ) parser.set_defaults(drop_privileges=True) parser.set_defaults(pointy=False) args = parser.parse_args() if args.led_rows != args.led_cols: print( os.path.basename(__file__) + ": error: led rows and columns must match") return True if args.led_chain * args.led_parallel != 6: print( os.path.basename(__file__) + ": error: total chained * parallel matrices must equal 6") return True options = RGBMatrixOptions() if args.led_gpio_mapping is not None: options.hardware_mapping = args.led_gpio_mapping options.rows = args.led_rows options.cols = args.led_cols options.chain_length = args.led_chain options.parallel = args.led_parallel options.row_address_type = args.led_row_addr_type options.multiplexing = args.led_multiplexing options.pwm_bits = args.led_pwm_bits options.brightness = args.led_brightness options.pwm_lsb_nanoseconds = args.led_pwm_lsb_nanoseconds options.led_rgb_sequence = args.led_rgb_sequence options.pixel_mapper_config = args.led_pixel_mapper options.panel_type = args.led_panel_type if args.led_show_refresh: options.show_refresh_rate = 1 if args.led_slowdown_gpio is not None: options.gpio_slowdown = args.led_slowdown_gpio if args.led_no_hardware_pulse: options.disable_hardware_pulsing = True if not args.drop_privileges: options.drop_privileges = False self.matrix = RGBMatrix(options=options) self.canvas = self.matrix.CreateFrameCanvas() self.matrix_size = args.led_rows self.chain_length = args.led_chain self.max_brightness = args.led_brightness self.run_time = args.t self.fade_time = args.f self.samples_per_pixel = args.a * args.a matrix_measure = args.e cube_measure = args.E self.spin_time = args.s try: image = Image.open(args.i) except FileNotFoundError: print( os.path.basename(__file__) + ": error: image file " + args.i + " not found") return True self.map_width = image.size[0] map_height = image.size[1] self.map_data = image.tobytes() # Longitude and latitude tables are 1-dimensional, # can do that because we iterate every pixel every frame. pixels = self.matrix.width * self.matrix.height subpixels = pixels * self.samples_per_pixel self.longitude = [0.0 for _ in range(subpixels)] self.latitude = [0 for _ in range(subpixels)] # imgbuf holds result for one face of cube self.imgbuf = bytearray(self.matrix_size * self.matrix_size * 3) coords = POINTY_COORDS if args.pointy else SQUARE_COORDS # Fill the longitude & latitude tables, one per subpixel. ll_index = 0 # Index into longitude[] and latitude[] arrays ratio = matrix_measure / cube_measure # Scale ratio offset = ((1.0 - ratio) + ratio / (self.matrix_size * args.a)) * 0.5 # Axis offset for face in range(6): upper_left = coords[VERTS[face][0]] upper_right = coords[VERTS[face][1]] lower_left = coords[VERTS[face][2]] for ypix in range(self.matrix_size): # For each pixel Y... for xpix in range(self.matrix_size): # For each pixel X... for yaa in range(args.a): # " antialiased sample Y... yfactor = offset + ratio * (ypix * args.a + yaa) / ( self.matrix_size * args.a) for xaa in range(args.a): # " antialiased sample X... xfactor = offset + ratio * ( xpix * args.a + xaa) / (self.matrix_size * args.a) # Figure out the pixel's 3D position in space... x3d = (upper_left[0] + (lower_left[0] - upper_left[0]) * yfactor + (upper_right[0] - upper_left[0]) * xfactor) y3d = (upper_left[1] + (lower_left[1] - upper_left[1]) * yfactor + (upper_right[1] - upper_left[1]) * xfactor) z3d = (upper_left[2] + (lower_left[2] - upper_left[2]) * yfactor + (upper_right[2] - upper_left[2]) * xfactor) # Then convert to polar coords on a sphere... self.longitude[ll_index] = ( (math.pi + math.atan2(-z3d, x3d)) / (math.pi * 2.0) * self.map_width) % self.map_width self.latitude[ll_index] = int( (math.pi * 0.5 - math.atan2( y3d, math.sqrt(x3d * x3d + z3d * z3d))) / math.pi * map_height) ll_index += 1 return False
first_run = True ledpi = LEDPi() while not run_once or first_run: first_run = False matrix = ledpi.display_clock() if matrix: send_matrix(driver, matrix) time.sleep(3) driver.Clear() if __name__ == '__main__': logging.basicConfig( level=logging.INFO, format='%(asctime)s [%(levelname)s] in %(funcName)s: %(message)s') parser = argparse.ArgumentParser() parser.add_argument('--run-once', action='store_true') args = parser.parse_args() options = RGBMatrixOptions() options.rows = 32 options.cols = 32 options.chain_length = 2 options.parallel = 1 options.multiplexing = 0 options.hardware_mapping = 'adafruit-hat-pwm' driver = RGBMatrix(options=options) main(driver, args.run_once)
# how many matrixes stacked horizontally and vertically matrix_horizontal = 5 matrix_vertical = 3 total_rows = matrix_rows * matrix_vertical total_columns = matrix_columns * matrix_horizontal options = RGBMatrixOptions() options.rows = matrix_rows options.cols = matrix_columns options.chain_length = matrix_horizontal options.parallel = matrix_vertical #options.hardware_mapping = 'adafruit-hat-pwm' # If you have an Adafruit HAT: 'adafruit-hat' #options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat' options.hardware_mapping = 'regular' options.gpio_slowdown = 2 matrix = RGBMatrix(options = options) ################################### # Main code ################################### icon_size = 40 fnt = ImageFont.truetype("Arial_Bold.ttf",10) fnt2 = ImageFont.truetype("Arial_Bold.ttf",12) fnt3 = ImageFont.truetype("Arial_Bold.ttf",16)
def init(): global toolDraw global myFont, myFontSmall, myFontMedium global rtcString global sec global matrix global ds3231 global COMport global buffer global rtc_str time.sleep(5) dataFile = open("/home/pi/kristallvelolite/count.txt", "r") data = dataFile.readlines() for i, temp in enumerate(data): record = list(map(int, temp.split())) key1 = "today "+str(i+1) key2 = "all " + str(i + 1) count[key1] = record[0] count[key2] = record[1] dataFile.close() # Vlad 11.06.2020 try: COMport = serial.Serial(serial_port, serial_speed, timeout=None) print(serial_port) except: COMport = serial.Serial("/dev/ttyUSB1", serial_speed, timeout=None) print('ComPort ttyUSB1') ############################## COMport.close() COMport.open() #Vlad 11.06.2020 COMport.reset_input_buffer() myFont = ImageFont.truetype(font_name, font_size) myFontSmall = ImageFont.truetype(font_name, small_font_size) myFontMedium = ImageFont.truetype(font_name, medium_font_size) buffer = Image.new("RGB", (768, 32), "black") toolDraw = ImageDraw.Draw(buffer) print_matrix(0, " 15:19\n 06.06.19", color1, myFontSmall) print_matrix(1, str(temperature)+"°C", color1, myFontMedium) print_matrix(2, str(count["today 1"]), color1, myFont) print_matrix(4, str(count["all 1"]), color2, myFont) print_matrix(6, " 15:19\n 06.06.19", color1, myFontSmall) print_matrix(7, str(temperature)+"°C", color1, myFontMedium) print_matrix(8, str(count["today 2"]), color1, myFont) print_matrix(10, str(count["all 2"]), color2, myFont) sec = 0 ds3231 = SDL_DS3231.SDL_DS3231(1, 0x68) rtc_str = ds3231.read_str() matrix_options = RGBMatrixOptions() matrix_options.rows = 32 matrix_options.cols = 64 matrix_options.chain_length = 12 matrix_options.parallel = 1 matrix_options.multiplexing = 1 matrix_options.hardware_mapping = 'adafruit-hat' matrix_options.gpio_slowdown = 2 matrix_options.pwm_bits = 1 #matrix_options.pwm_dither_bits = 1 matrix_options.brightness = 100 matrix_options.pwm_lsb_nanoseconds = 350 matrix = RGBMatrix(options = matrix_options) matrix.SetImage(buffer, 0, 0)
def draw_board(): """Draw components of MLB game. Firstly, creates a canvas for the LED matrix using various configurations. Requests games for the day for MLB and draws various components of the game such as team logos, scores, period, and time. Also, draws "SCORE!!!" animation for the game if there is an update in the score. If button is pressed during the execution, it will load the next game. If the game is the last one for the day in MLB, then it will go to the next league. Returns: int: Return -1 if no favorite game. """ # Configuration for the matrix options = RGBMatrixOptions() options.rows = ROWS options.cols = COLS options.chain_length = 1 options.parallel = 1 options.brightness = BRIGHTNESS options.hardware_mapping = 'adafruit-hat' image_size = ROWS if ROWS < COLS else COLS matrix = RGBMatrix(options=options) canvas = matrix.CreateFrameCanvas() font = graphics.Font() font.LoadFont("./fonts/tom-thumb.bdf") anifont = graphics.Font() anifont.LoadFont("./fonts/cherry-10-b.bdf") textColor = graphics.Color(225, 225, 0) height_first_row = 9 height_second_row = 18 height_third_row = 27 # Control button button = Button(GPIO_CONTROL) it = 0 wait = 0 # Loading MLB canvas.Clear() graphics.DrawText(canvas, font, 10, height_second_row, textColor, 'Loading MLB') canvas = matrix.SwapOnVSync(canvas) games = Scores.get_scores() if len(games) == 0: # Print no games scheduled canvas.Clear() graphics.DrawText(canvas, font, 4, height_second_row, textColor, 'MLB - no games') canvas = matrix.SwapOnVSync(canvas) # Handle control button and wait button.wait_for_press(15) return -1 while it < len(games): canvas.Clear() score_len = 20 if 'score' in games[it]: # Chagne score len if 2 digit score score_len = 28 if games[it]['score'][3] == '-' else 20 # Get x coords for logos image_space = (COLS - score_len - 4) / 2 x_away = -ROWS + image_space - 2 x_home = image_space + score_len + 2 # Get logos as thumbnails; home is flipped for right image_away = Image.open(f"logos/MLB/{games[it]['away']}_logo.png") image_away.thumbnail((image_size, image_size), Image.ANTIALIAS) image_home = Image.open(f"logos/MLB/{games[it]['home']}_logo.png") image_home.thumbnail((image_size, image_size), Image.ANTIALIAS) # Print logos canvas.SetImage(image_away.convert('RGB'), x_away, 0) canvas.SetImage(image_home.convert('RGB'), x_home, 0) # Print score final or live score_len = len(games[it]['score']) * 4 if games[it]['stage'] == 'In Progress': # If game is in progress, print period \ # and time left in the period period_len = len(games[it]['period']) * 4 graphics.DrawText(canvas, font, int((COLS - period_len) / 2), height_first_row, textColor, games[it]['period']) graphics.DrawText(canvas, font, int((COLS - score_len) / 2), height_second_row, textColor, games[it]['score']) elif games[it]['stage'] == 'Final': # Else print 'fin' to indicate final score graphics.DrawText(canvas, font, int((COLS - 12) / 2), height_first_row, textColor, "FIN") graphics.DrawText(canvas, font, int((COLS - score_len) / 2), height_second_row, textColor, games[it]['score']) else: # If planned game, print @ and time period_len = len(games[it]['period']) * 4 graphics.DrawText(canvas, font, int((COLS - 8) / 2), height_first_row, textColor, "AT") graphics.DrawText(canvas, font, int( (COLS - period_len) / 2), height_second_row, textColor, games[it]['period']) graphics.DrawText(canvas, font, int((COLS - 16) / 2), height_third_row, textColor, 'HOME') # Handle control button and wait is_button_pressed = button.wait_for_press(5) # Increment iterator if button was pressed if is_button_pressed: it += 1 time.sleep(1) # Mention to the user that they should wait after pressing the button # for about 5-10 seconds as it takes a while to fetch score wait += 1 if wait > 12 and it < len(games): wait = 0 tmp = Scores.get_scores() # Check if new fixes if games[it]['away'] != games[it]['away'] and \ tmp[it]['home'] != tmp[it]['home']: it = 0 elif games[it]['stage'] == 'In Progress' and games[it][ 'score'] != tmp[it]['score']: # check for score update pos = ROWS rounds = 0 while True: canvas.Clear() l = graphics.DrawText(canvas, anifont, pos, height_second_row, textColor, 'SCORE!!!') pos -= 1 if (pos + l < 0): pos = ROWS rounds += 1 if rounds > 3: break time.sleep(0.05) canvas = matrix.SwapOnVSync(canvas) games = tmp canvas = matrix.SwapOnVSync(canvas)
gif_folder_name = "dank_gifs" os.chdir(os.getcwd() + "/" + gif_folder_name) #juicy list comprehension img_list = [ filename for filename in os.listdir(os.getcwd()) if filename.endswith(".gif") ] # Configuration for the matrix options = RGBMatrixOptions() options.rows = 64 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat' options.gpio_slowdown = 4 options.brightness = 50 matrix = RGBMatrix(options=options) loop_num = 3 while (True): random.shuffle(img_list) for gif in img_list: image = Image.open(gif) loop_times = loop_num if image.n_frames < 50 else 1 #loop_times = loop_num if image.n_frames < 50 else 1 for i in range(0, loop_times): for frame in range(0, image.n_frames): image.seek(frame)
def to_matrix(_minutes): # matrix options set here options = RGBMatrixOptions() options.rows = 32 options.chain_length = 2 options.hardware_mapping = 'adafruit-hat' options.parallel = 1 # orient_image arguments here mat_x = options.chain_length * options.rows mat_y = options.rows char_w = 8 char_h = 13 num_chars = 8 lines= 1 O = orient_image(mat_x, mat_y, char_w ,char_h, num_chars,lines) matrix = RGBMatrix(options = options) image = Image.new("RGB", (64, 32)) draw = ImageDraw.Draw(image) matrix.Clear() # image files found in respective directories png = PNG_8x13 # create the countdown timer here # First for loop takes the initial list of lists and starts itering through #print(T) #timer_flag = True while True: T = test_timer(_minutes) for i in T: #print('here') # Second for loop takes each individual list itme and iters through, printing to the matrix #print(i) # this updates later according to the offset x_matrix_pos = O[0] # with a single row of chars this wont change y_matrix_pos = O[1] # this is how far away the next char will print from the previous x_matrix_offset = O[2] #print(i) minutes = (i[0],i[1]) seconds = (i[2],i[3]) hundreths = (i[4],i[5]) for i in minutes: #sleep(.01) #x_matrix_pos = x_matrix_offset image = Image.open("%s" % png[int(minutes[0])]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) x_matrix_pos += x_matrix_offset #print x_matrix_pos image = Image.open("%s" % png[int(minutes[1])]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) #colon x_matrix_pos += x_matrix_offset image = Image.open("%s" % png[10]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) #for secs in seconds: x_matrix_pos += x_matrix_offset image = Image.open("%s" % png[int(seconds[0])]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) x_matrix_pos += x_matrix_offset #image = Image.open("%s" % png[int(seconds[1])]) image = Image.open("%s" % png[int(seconds[1])]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) #period x_matrix_pos += x_matrix_offset image = Image.open("./8x13/period.png") image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) #for hunds in hundreths: x_matrix_pos += x_matrix_offset image = Image.open("%s" % png[int(hundreths[0])]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) x_matrix_pos += x_matrix_offset image = Image.open("%s" % png[int(hundreths[1])]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) #print(minutes[0],minutes[1],seconds[0],seconds[1],hundreths[0],hundreths[1]) sleep(.0001693405867) #timer_flag == False print(datetime.now()) while 1: # last list item in timer zero_status = T[-1] x_matrix_pos = O[0] y_matrix_pos = O[1] x_matrix_offset = O[2] for i in zero_status: image = Image.open("%s" % png[i]) image.load() matrix.SetImage(image.convert('RGB'),x_matrix_pos, y_matrix_pos) x_matrix_pos += x_matrix_offset
import subprocess import os import random import time import datetime import numpy as np import scipy.misc as misc from rgbmatrix import RGBMatrix, RGBMatrixOptions dir_path = os.path.dirname(os.path.realpath(__file__)) options = RGBMatrixOptions() options.rows = 32 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'adafruit-hat-pwm' options.multiplexing = 1 options.pwm_bits = 8 options.scan_mode = 0 options.gpio_slowdown = 1 options.pwm_lsb_nanoseconds = 260 #options.show_refresh_rate = 1 #options.daemon = 1 runthrough_min = 10 matrix = RGBMatrix(options=options) radius = 12 * 10 start = 160 - radius diameter = radius * 2
from PIL import Image from PIL import ImageDraw from PIL import ImageFont import time from rgbmatrix import RGBMatrix, RGBMatrixOptions import random import pyaudio import numpy as np # Configuration options = RGBMatrixOptions() options.rows = 64 options.cols = 64 options.chain_length = 1 options.parallel = 1 options.hardware_mapping = 'adafruit-hat-pwm' # regular // adafruit-hat // adafruit-hat-pwm colourchg = 32 # how much colours will change by rotateresample = Image.BICUBIC # Method for rotating image: PIL.Image.NEAREST (fastest) // PIL.Image.BILINEAR // Image.BICUBIC audiodevice = 0 # Audio input device to use (see list generated at startup) # Init Audio audiobuffer = 1024 p = pyaudio.PyAudio() for i in range(p.get_device_count()): dev = p.get_device_info_by_index(i) print p.get_device_info_by_index(i)['index'], p.get_device_info_by_index( i)['name'] stream = p.open(format=pyaudio.paInt16,