樹莓派與傳感器
  • 前言
  • 樹莓派基礎
  • 樹莓派與Arduino
  • 樹莓派與Microbit
  • 用Python點亮LED
  • 把玩三色LED燈與PWM呼吸燈
  • 蜂鳴器
  • 按鈕開關
  • 人體移動感應器(PIR)
  • 尋線、避障與測距
  • 樹莓派:類比轉數位處理
  • 溫溼度感測器DHT11
  • 簡易的心跳偵測模組零件
  • 聲音感測器
  • 與火災相關的警報零組件
  • DS18B20溫度感測器
  • TM1638七節LED顯示器
  • MAX7219與矩陣式LED
  • 液晶顯示LCD1602
  • Django與物聯網
  • 使用VS Code遠端開發Django
  • 樹莓派與自走車
    • 控制馬達正反轉基礎
      • 自走車方向控制
    • 遠端鍵盤控制自走車+WebCam
    • 使用網路與搖桿、手機控制
  • 樹莓派與紅外線遙控器
  • 遠端GPIO:pigpio + piscope
Powered by GitBook
On this page

Was this helpful?

MAX7219與矩陣式LED

PreviousTM1638七節LED顯示器Next液晶顯示LCD1602

Last updated 6 years ago

Was this helpful?

樹莓派透過SPI協定與MAX7219進行溝通,再由這個控制晶片去控制矩陣式LED,日後當面對較為複雜的零組件時,通常不會由樹莓派直接去操控它,而是透過其它晶片去間接操控,這些控制晶片除了官方本身提供相關的驅動程式或是相關函數外,也有許多網路熱心人士提供更多的Python模組,這次使用的是:

from luma.led_matrix.device import max7219
from luma.core.interface.serial import spi
from luma.core.render import canvas
from luma.core.legacy import text, show_message
from luma.core.legacy.font import proportional, CP437_FONT, TINY_FONT, SINCLAIR_FONT, LCD_FONT
import time

serial = spi(port=0, device=0)
device = max7219(serial, cascaded=1, block_orientation=0, rotate=0)
print("Created device")
# start demo
msg = "12345678"
print(msg)
show_message(device, msg, fill="white", font=proportional(CP437_FONT))
time.sleep(1)

msg = "Slow"
print(msg)
show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1)

time.sleep(1)
device.contrast(0x60)
with canvas(device) as draw:
    text(draw, (0, 0), "A", fill="white", font=proportional(CP437_FONT))
time.sleep(2)

with canvas(device) as draw:
    draw.rectangle(device.bounding_box, outline="white", fill="black")
    # time.sleep(2)
    # 僅一個 8*8 看不出橢圓的形狀
    # draw.ellipse([(0, 0), (7, 7)], outline="white", fill="black")

time.sleep(2)

for _ in range(5):
    for intensity in range(16):
        device.contrast(intensity * 16)
        time.sleep(0.1)

device.contrast(0x80)
time.sleep(1)
GitHub - rm-hull/luma.led_matrix: Python module to drive LED Matrices & 7-segment displays (MAX7219) and RGB NeoPixels (WS2812 / APA102)GitHub
Logo