def demo(): DISPLAYTEST = 0x0F SHUTDOWN = 0x0C INTENSITY = 0x0A DECODEMODE = 0x09 SCANLIMIT = 0x0B # Create an spi instance serial = spi(port=0, device=0, gpio=noop()) # Change the brightness serial.data([INTENSITY, 0x70 >> 4] * 64) # Not sure what this does serial.data([SCANLIMIT, 7] * 32) # Select how the data will be decoded serial.data([DECODEMODE, 0] * 64) # hide each light serial.data([SHUTDOWN, 0] * 64) time.sleep(1) serial.data([0x01, 0b01111110]) serial.data([0x02, 0b10000001]) serial.data([0x03, 0b10011001]) serial.data([0x04, 0b10000001]) serial.data([0x05, 0b10000001]) serial.data([0x06, 0b10011001]) serial.data([0x07, 0b10000001]) serial.data([0x08, 0b01111110]) # show each light time.sleep(1) serial.data([SHUTDOWN, 1] * 64)
def main(): # Setup for Banggood version of 4 x 8x8 LED Matrix (https://bit.ly/2Gywazb) serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=4, block_orientation=-90, blocks_arranged_in_reverse_order=True) device.contrast(16) # The time ascends from the abyss... animation(device, 8, 1) toggle = False # Toggle the second indicator every second while True: toggle = not toggle sec = datetime.now().second if sec == 59: # When we change minutes, animate the minute change minute_change(device) elif sec == 30: # Half-way through each minute, display the complete date/time, # animating the time display into and out of the abyss. full_msg = time.ctime() animation(device, 1, 8) show_message(device, full_msg, fill="white", font=proportional(CP437_FONT)) animation(device, 8, 1) else: # Do the following twice a second (so the seconds' indicator blips). # I'd optimize if I had to - but what's the point? # Even my Raspberry PI2 can do this at 4% of a single one of the 4 cores! hours = datetime.now().strftime('%H') minutes = datetime.now().strftime('%M') with canvas(device) as draw: text(draw, (0, 1), hours, fill="white", font=proportional(CP437_FONT)) text(draw, (15, 1), ":" if toggle else " ", fill="white", font=proportional(TINY_FONT)) text(draw, (17, 1), minutes, fill="white", font=proportional(CP437_FONT)) time.sleep(0.5)
def demo(): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=32, height=8, block_orientation=-90, rotate=2) # Create The Message msg = "Devscover Subscribers: " try: url = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=UC7jBsNZf-wRyJkEmDKBrg2A&key=XXXX" res = urllib.request.urlopen(url) data = json.load(res) subs = data['items'][0]['statistics']['subscriberCount'] except: subs = 'cant load' msg_to_show = msg + subs # Start The Display print(msg_to_show) show_message(device, msg_to_show, fill="white", font=proportional(CP437_FONT)) time.sleep(1)
def __init__(self): serial = spi(port=0, device=0, gpio=noop()) led_matrix = max7219(serial, cascaded=4, block_orientation=90, rotate=0, blocks_arranged_in_reverse_order=True) self.device = led_matrix
def clock(n, block_orientation, rotate): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=8, block_orientation=-90, rotate=rotate) print("Ora") msg = ora + " : " + perc print(msg) show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(1)
def __init__(self): serial = spi(port=0, device=0, gpio=noop(), cs_high=True) self._device = max7219(serial) self._virtual = viewport(self._device, width=8, height=8) self._state = 'play' self._interval = 0.15 self._lines = [] self._score = 0
def main(): # create seven segment device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1) seg = sevensegment(device) #orig_demo(serial, device, seg) #clock(seg, seconds=10) show_message_vp(device, "you are the best Mr. Shivakumar", 0.5)
def __init__(self, interval): self.interval = interval serial = spi(port=0, device=0, gpio=noop()) self.device = max7219(serial) self._timer = None self.is_running = False self.timeout = None self.start()
def hofok(n, block_orientation, rotate): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=8, block_orientation=-90 , rotate=rotate) print("Hofok") msg = "Muhahhaa." print(msg) show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(1)
def __init__(self): serial = spi(port=0, device=0, gpio=noop()) self.device = max7219(serial, width=32, height=8, block_orientation=90, blocks_arranged_in_reverse_order=False) print("Created device")
def demo(n, block_orientation, rotate, msg): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0) show_message(device, msg, fill="white", font=proportional(LCD_FONT))
def test_cleanup(): gpio_LIGHT = 11 device = backlit_device(serial_interface=noop(), gpio=gpio, gpio_LIGHT=gpio_LIGHT) gpio.reset_mock() device.cleanup() gpio.output.assert_called_once_with(gpio_LIGHT, gpio.HIGH)
def Sajatszoveg(n, block_orientation, rotate, sajat_szov): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=8, block_orientation=-90, rotate=rotate) if ((now.hour + 1) < 9 or (now.hour + 1) > 19): device.contrast(1) print("Kisebb fényerő") msg = sajat_szov msg = nem_ascii_karakterek_eltavolitasa_sajat_szoveg(msg)
def __init__(self): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1) device.contrast(15) self.seg = sevensegment(device) self.update_clock() self.messages = [] self.t0 = time.time()
def test_active_low_enable_off(): gpio_LIGHT = 19 device = backlit_device(serial_interface=noop(), gpio=gpio, gpio_LIGHT=gpio_LIGHT) gpio.reset_mock() device.backlight(False) gpio.output.assert_called_once_with(gpio_LIGHT, gpio.HIGH)
def scroller(): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=4, block_orientation=-90, rotate=0) # start demo msg = "NOW PLAYING: " show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(1)
def main(): temp = Temperatura() datos=temp.datos_sensor() matriz = Matriz(numero_matrices=2, ancho=16) mensaje=datos['temperatura'] + ' ' + datos['humedad'] + ' ' matriz.mostrar_mensaje(mensaje, delay=0.3) serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width, height, cascaded, rotate) show_message(device, msg, font,)max7219(serial, width, height, cascaded, rotate)
def create_device(self) -> device: if self.debug: return pygame(width=32, height=8) else: serial = spi(gpio=noop()) return max7219(serial, cascaded=4, block_orientation=-90, contrast=0)
def __init__(self, port: int = 0, device: int = 0, cascaded: int = 1): self.serial = spi(port=port, device=device, gpio=noop()) self.cascaded = cascaded self.device = max7219(self.serial, cascaded=cascaded) self.height = 8 self.width = 8 * cascaded self.data = np.full((self.height, self.width), False)
def initDisplay(n, block_orientation, rotate): global device # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0) print("Created device")
def test_unsupported_platform(): e = RuntimeError('Module not imported correctly!') errorgpio = Mock(unsafe=True) errorgpio.setup.side_effect = e try: backlit_device(serial_interface=noop(), gpio_LIGHT=19, gpio=errorgpio) except luma.core.error.UnsupportedPlatform as ex: assert str(ex) == 'GPIO access not available'
def config_matriz(cant_matrices=2, orientacion=0, rotacion=0, ancho=8, alto=8): font = [CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT] serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=ancho, height=alto, cascaded=cant_matrices, rotate=rotacion) return font, device
def show(emu=False, of): if emu: #para emular pido el device device = get_device() datos = {'temperatura': 34, 'humedad': 89} else: #Inicializar la matriz: identificar puerto serial = spi(port=0, device=0, gpio=noop()) #crear una insctancia del objeto device = max7219(serial, cascaded=2, block_orientation=0) #leer temperatura y humedad del sensor tmp = Temperatura() datos = tmp.datos_sensor() print('Temperatura = {0:0.1f°}C Humedad = {1:0.1f} %'.format( datos['temperatura'], datos['humedad'])) ################## por si es necesario realizar conversiones temp = datos['temperatura'] hum = datos['humedad'] msg = "Oficina " + of print(msg) show_message(device, msg, fill='white', font=proportional(LCD_FONT), scroll_delay=0.05) msg = 'Temperatura' show_message(device, msg, fill='white', font=proportional(LCD_FONT), scroll_delay=0.05) msg = str(temp) + 'º C' with canvas(device) as draw: text(draw, (1, 0), msg, fill="white") time.sleep(3) msg = 'Humedad' show_message(device, msg, fill='white', font=proportional(LCD_FONT), scroll_delay=0.05) msg = str(hum) + '%' with canvas(device) as draw: text(draw, (1, 0), msg, fill="white") time.sleep(3) msg = 'Bye!' show_message(device, msg, fill='white', font=proportional(LCD_FONT), scroll_delay=0.05) guardar_datos(of, temp, hum)
def __init__(self, queue, default_message, **kwargs): super(Worker, self).__init__() self.queue = queue self.default_message = default_message self.kwargs = kwargs serial = spi(port=0, device=0, gpio=noop()) self.device = max7219(serial) self.images = [] self.current_frame = 0
def test_pwm_turn_on(): gpio_LIGHT = 18 pwm_mock = Mock() gpio.PWM.return_value = pwm_mock device = backlit_device(serial_interface=noop(), gpio=gpio, gpio_LIGHT=gpio_LIGHT, pwm_frequency=100) gpio.PWM.assert_called_once_with(gpio_LIGHT, 100) gpio.reset_mock() device.backlight(True) pwm_mock.ChangeDutyCycle.assert_called_once_with(100.0)
def matrix(price): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=32, height=8, block_orientation=90) with canvas(device) as draw: # 숫자 하나당 4 digits = len(price) * 4 text(draw, (32 - digits, 0), price, fill="white", font=TINY_FONT) return jsonify({"result": True})
def initialize_device(): serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, rotate=2, height=8, width=32, block_orientation=90) return serial, device
def main(): """Shows basic usage of the Google Calendar API. Prints the start and name of the next 10 events on the user's calendar. """ creds = None # The file token.pickle stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. if os.path.exists('token.pickle'): with open('token.pickle', 'rb') as token: creds = pickle.load(token) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: flow = InstalledAppFlow.from_client_secrets_file( '/home/pi/.creds.json', SCOPES) creds = flow.run_local_server() # Save the credentials for the next run with open('token.pickle', 'wb') as token: pickle.dump(creds, token) service = build('calendar', 'v3', credentials=creds) # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=8, block_orientation=90, rotate=0) print("Created device") start = time.perf_counter() while (start + 550) > time.perf_counter(): # Call the Calendar API now = datetime.datetime.utcnow().isoformat( ) + 'Z' # 'Z' indicates UTC time # print('Getting the upcoming 10 events') events_result = service.events().list( calendarId= '*****@*****.**', timeMin=now, maxResults=7, singleEvents=True, orderBy='startTime').execute() events = events_result.get('items', []) msg = '' if not events: msg = '- finner ingen middager - ' for event in events: msg = dayText(event) show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(2)
def __init__(self): super().__init__() self.is_busy = False self.current_message = None # create matrix device self.serial = spi(port=0, device=0, gpio=noop()) self.device = max7219(self.serial, cascaded=4, block_orientation=-90, rotate=0) self.device.contrast(0x09) print("Created device")
def demo(n, block_orientation, rotate, inreverse): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse) msg = "Hello World! " print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1)
def init_device(port=0, device_id=0, cascaded=1, contrast=127): '''Initialize both the raw matrix device and sevensegment abstraction. Each is used by the different effects generated below. ''' serial = spi(port=port, device=device_id, gpio=noop()) device = led(serial) seg = sevensegment(device) device.contrast(contrast) return device, seg
def demo(w, h, block_orientation, rotate): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, width=w, height=h, rotate=rotate, block_orientation=block_orientation) print("Created device") with canvas(device) as draw: draw.rectangle(device.bounding_box, outline="white") text(draw, (2, 2), "Hello", fill="white", font=proportional(LCD_FONT)) text(draw, (2, 10), "World", fill="white", font=proportional(LCD_FONT)) time.sleep(300)
def main(): # create seven segment device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=1) seg = sevensegment(device) print('Simple text...') for _ in range(8): seg.text = "HELLO" time.sleep(0.6) seg.text = " GOODBYE" time.sleep(0.6) # Digit slicing print("Digit slicing") seg.text = "_" * seg.device.width time.sleep(1.0) for i, ch in enumerate([9, 8, 7, 6, 5, 4, 3, 2]): seg.text[i] = str(ch) time.sleep(0.6) for i in range(len(seg.text)): del seg.text[0] time.sleep(0.6) # Scrolling Alphabet Text print('Scrolling alphabet text...') show_message_vp(device, "HELLO EVERYONE!") show_message_vp(device, "PI is 3.14159 ... ") show_message_vp(device, "IP is 127.0.0.1 ... ") show_message_alt(seg, "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ") # Digit futzing date(seg) time.sleep(5) clock(seg, seconds=10) # Brightness print('Brightness...') for x in range(5): for intensity in range(16): seg.device.contrast(intensity * 16) time.sleep(0.1) device.contrast(0x7F)
def demo(n, block_orientation): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation) print("Created device") print("Drawing on Canvas stage 1") #with canvas(device) as draw: for abc in range(1): with canvas(device) as draw: for y in range(8): for x in range(8): #print("Point " + str(x) + " " + str(y)) draw.point((x, y ), randint(0,1)) time.sleep(0.1) print("Finished Drawing on Canvas stage 2")
def __init__(self): rospy.init_node('display') self.rate=100 self.serial = spi(port=0, device=0, gpio=noop()) self.device = max7219(self.serial, cascaded=1, block_orientation=0) self.shift_counter=0 self.peak_counter=3 self.processing_count=0 self.show_grec_bool=False print("Created device") # Init Subscribers rospy.Subscriber("disp/text", String, self.show_text_message) rospy.Subscriber("disp/emotion", disp_emotion, self.emotion) rospy.Subscriber("disp/action", disp_action, self.action) # Init services s_dis = rospy.Service('stop_disp', Empty, self.stop_disp) i_proc = rospy.Service('inc_proc', Empty, self.increase_processing_count) dec_proc = rospy.Service('dec_proc', Empty, self.decrease_processing_count) grec = rospy.Service('show_grec', Empty, self.show_grec) lrec = rospy.Service('show_lrec', Empty, self.show_lrec) self.display_anim=False
def demo(n, block_orientation, rotate, inreverse): # create matrix device serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation, rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse) print("Created device") # start demo msg = "MAX7219 LED Matrix Demo" print(msg) show_message(device, msg, fill="white", font=proportional(CP437_FONT)) time.sleep(1) msg = "Fast scrolling: Lorem ipsum dolor sit amet, consectetur adipiscing\ elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut\ enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\ aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in\ voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint\ occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit\ anim id est laborum." msg = re.sub(" +", " ", msg) print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0) msg = "Slow scrolling: The quick brown fox jumps over the lazy dog" print(msg) show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1) print("Vertical scrolling") words = [ "Victor", "Echo", "Romeo", "Tango", "India", "Charlie", "Alpha", "Lima", " ", "Sierra", "Charlie", "Romeo", "Oscar", "Lima", "Lima", "India", "November", "Golf", " " ] virtual = viewport(device, width=device.width, height=len(words) * 8) with canvas(virtual) as draw: for i, word in enumerate(words): text(draw, (0, i * 8), word, fill="white", font=proportional(CP437_FONT)) for i in range(virtual.height - device.height): virtual.set_position((0, i)) time.sleep(0.05) msg = "Brightness" print(msg) show_message(device, msg, fill="white") time.sleep(1) with canvas(device) as draw: text(draw, (0, 0), "A", fill="white") time.sleep(1) for _ in range(5): for intensity in range(16): device.contrast(intensity * 16) time.sleep(0.1) device.contrast(0x80) time.sleep(1) msg = "Alternative font!" print(msg) show_message(device, msg, fill="white", font=SINCLAIR_FONT) time.sleep(1) msg = "Proportional font - characters are squeezed together!" print(msg) show_message(device, msg, fill="white", font=proportional(SINCLAIR_FONT)) # http://www.squaregear.net/fonts/tiny.shtml time.sleep(1) msg = "Tiny is, I believe, the smallest possible font \ (in pixel size). It stands at a lofty four pixels \ tall (five if you count descenders), yet it still \ contains all the printable ASCII characters." msg = re.sub(" +", " ", msg) print(msg) show_message(device, msg, fill="white", font=proportional(TINY_FONT)) time.sleep(1) msg = "CP437 Characters" print(msg) show_message(device, msg) time.sleep(1) for x in range(256): with canvas(device) as draw: text(draw, (0, 0), chr(x), fill="white") time.sleep(0.1)
from luma.core.interface.serial import spi, noop from luma.core.render import canvas from luma.led_matrix.device import max7219 from time import sleep serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial) #font = ImageFont.truetype("examples/pixelmix.ttf", 8) #with canvas(device) as draw: # draw.rectangle(device.bounding_box, outline="white", fill="black") #sleep(2) import random from PIL import Image image = Image.new('1', (8, 8)) while True: x = random.randint(0,7) y = random.randint(0,7) image.putpixel((x, y), 1) device.display(image) sleep(.05) image.putpixel((x, y), 0) device.display(image)