def __init__(self): self.M_LED_NUM = 4 self.M_LED_SCROLL_DELAY = 0.09 cs_pin_pico = 5 spi = SPI(0) self.display = display.Matrix8x8(spi=spi, cs=Pin(cs_pin_pico), num=self.M_LED_NUM) self.display.brightness(2)
def dp(self): spi = SPI(baudrate=100000, polarity=1, phase=0, mosi=Pin(27), sck=Pin(25), miso=Pin(33)) self.display = max7219.Matrix8x8(spi, Pin(26), 4)
def __init__(self): self.MAX7219_NUM = 4 self.MAX7219_INVERT = False self.MAX7219_SCROLL_DELAY = 0.1 cs_pin = 5 spi = SPI(0) self.display = max7219.Matrix8x8(spi=spi, cs=Pin(cs_pin), num=self.MAX7219_NUM) self.display.brightness(2)
def __init__(self): self.state = SignState.DEMO self.task = None self.spi = SPI(1, baudrate=10000000) self.board = max7219.Matrix8x8(self.spi, Pin(Gpio.CS), 1) self.effects = Effects(self.board) self.loop = asyncio.get_event_loop() self.setState()
def switch_matrix(self): if self.tft: self.tft.deinit() self.tft = 0 if not self.spi: spi = SPI(spihost=1, baudrate=8000000, miso=Pin(pd.PIN_MISO), mosi=Pin(pd.PIN_MOSI), sck=Pin(pd.PIN_SCK)) led_right = max7219.Matrix8x8(spi, Pin(pd.PIN_8X8_1_CS), 4) led_right.brightness(2) led_right.fill(0) led_right.show() led_left = max7219.Matrix8x8(spi, Pin(pd.PIN_8X8_2_CS), 4) led_left.brightness(2) led_left.fill(0) led_left.show() self.spi = spi self.led_right = led_right self.led_left = led_left
def __init__(self, SPIpin=15, screens=4): 'afhankelijkheid: https://github.com/mcauser/micropython-max7219' self.spi = SPI(1, baudrate=10000000, polarity=0, phase=0) self.display = max7219.Matrix8x8(self.spi, Pin(SPIpin), screens) self.display.brightness(0) self.display.fill(0) self.display.show() self.__debug = False self.display.text('----', 0, 0, 1) self.display.show() time.sleep(0.05) self.display.fill(0) self.display.show() time.sleep(0.05)
def __init__(self, spi_num=2, sck_pin=Pin(18), mosi_pin=Pin(23), cs_pin=Pin(5), screen_count=6): self.spi_num = spi_num self.sck_pin = sck_pin self.mosi_pin = mosi_pin self.cs_pin = cs_pin self.screen_count = screen_count self.spi = SPI(self.spi_num, sck=self.sck_pin, mosi=self.mosi_pin) self.display = max7219.Matrix8x8(self.spi, self.cs_pin, self.screen_count) self.uri = 'https://devvoh.com/tally-2018/export-latest-mutation' self.response = None self.created_at_timestamp = 0 self.network_delay_ms = 200 self.scroll_delay_ms = 125
def init_display(): spi = SPI(1, baudrate=10000000, polarity=0, phase=0) display = max7219.Matrix8x8(spi, Pin(15), 8) display.brightness(0) return display
gc.collect() print("Good Morning") # Available pins # 0, 2, 4, 5, 12, 13, 14, 15, and 16 # Pin(2) == GPIO2 == D4 # Pin(4) == GPIO4 == D2 # Pin(5) == GPIO5 == D1 # Pin(12) == GPIO12 == D6 # Pin(14) == GPIO14 == D5 # Pin(16) == GPIO16 == D0 (unused) spi = SPI(-1, baudrate=100000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(4), miso=Pin(16)) display = max7219.Matrix8x8(spi, Pin(5), 5) gc.collect() from BME280_min import BME280 CLOCK_ICON = bytearray([0x3c,0x52,0x91,0x91,0x8d,0x81,0x42,0x3c]) WIFI_ICON = bytearray([0xf0,0x08,0xe4,0x12,0xc9,0x25,0x15,0x95]) TRAIN_ICON = bytearray([0x08,0x04,0xE0,0xA4,0xBE,0x82,0xFE,0x24]) SOLAR_ICON = bytearray([0x00,0xFC,0xAA,0xAA,0x7E,0x55,0x55,0x3F]) BATT_ICON = bytearray([0x18,0x7E,0x42,0x4A,0x5A,0x52,0x42,0x7E]) PLUG_ICON = bytearray([0x00,0x00,0x06,0x0B,0x72,0xCB,0x06,0x00]) BOLT_ICON = bytearray([0x00,0x04,0x08,0x10,0x3C,0x08,0x10,0x20]) gc.collect()
import max7219 from machine import Pin, SPI, freq import utime #increase CPU clock to 160 MHz freq(160000000) #initiate the SPI connection of led matrix spi = SPI(1, baudrate=10000000, polarity=0, phase=0) device = max7219.Matrix8x8(spi, Pin(2), 1) device.fill(0) device.brightness(10) utime.sleep(0.1) device.show() def getbase(angle): if angle == 0: base_x = 0 base_y = 0 elif angle == 180: base_x = 7 base_y = 7 return (base_x, base_y) #rotate the display orientation to 180 degrees axis = getbase(180) base_x = axis[0] base_y = axis[1]
import max7219, json import time from machine import Pin, SPI spi = SPI(1, baudrate=400000, polarity=1, phase=0, sck=Pin(4), mosi=Pin(2)) ss = Pin(5, Pin.OUT) display = max7219.Matrix8x8(spi, ss, 16) def image(img_list): st = time.ticks_ms() display.fill(0) for i in img_list: display.hline(32 * (i[1] // 8) + i[0], i[1] % 8, i[2], 1) display.show() c = time.ticks_ms() - st if c < 100: time.sleep_ms(90 - c) with open('bad.data', 'r') as f: for i in f: try: z = json.loads(i) image(z) except Exception as e: pass gc.collect()
import machine, time, max7219, mpu6050 spi = machine.SPI(-1, 10000000, miso=machine.Pin(2), mosi=machine.Pin(13), sck=machine.Pin(14)) display = max7219.Matrix8x8(spi, machine.Pin(12)) display.fill(0) display.brightness(1) display.show() m = mpu6050.MPU(scl=22, sda=21, intr=16, d=display) while not m.calibrated: m.calibrate() acx, acy, acz, seq, gx, gy, gz = 0, 0, 0, 0, 0, 0, 0 starttime = int(time.time()) while True: try: acx, acy, acz, seq, gx, gy, gz = m.read_sensors_scaled() except: pass if sum([abs(x) for x in [acx, acy, acz, gx, gy, gz]]) > 50: starttime = int(time.time()) seconds = int(time.time()) - starttime hrs = '%02d' % (seconds / 3600)
import max7219 import uasyncio from machine import Pin, SPI, PWM spi = SPI(-1, 10000000, miso=Pin(19), mosi=Pin(23), sck=Pin(18)) display = max7219.Matrix8x8(spi, Pin(17), 4) display.brightness(15) buz_ch1 = PWM(Pin(19), freq=440, duty=0) pwm_duty = 100 async def file_to_led(): while True: with open('ledtext.txt', 'r') as f: for l in f: print(l) display.fill(0) display.text(l, 0, 0, 1) display.show() await uasyncio.sleep(0.5) display.fill(0) display.show() await uasyncio.sleep(1) async def temp(): import dht from time import sleep
def main(): # Setup display spi = SPI(1, baudrate=10000000, polarity=0, phase=0) display = max7219.Matrix8x8(spi, Pin(15), 12) display.brightness(0) displayText(display, 'Init', 1) np = neopixel.NeoPixel(machine.Pin(4), 4) np[ledPower] = Red #(neoMid, neoLow, neoLow) # Red np[0] = Purple np[1] = Purple np[2] = Green np.write() # Init the display time variables initLoop = True currHour = 0 lastHour = 0 hourChanged = False currMinute = 0 lastMinute = 0 minuteChanged = False timeNow = (0, 0, 0, 0, 0, 0, 0, 0) displayTimeNow = '' displayTimeLast = '' # Set the RTC displayText(display, 'NTP', 1) settime() rtc = RTC() displayText(display, 'Done', 1) np[0] = Black np[1] = Black np[2] = Black np.write() while True: print('Looop') timeNow = rtc.datetime() currHour = timeNow[4] currMinute = timeNow[5] if currHour != lastHour: np[2] = Green np.write() settime() timeNow = rtc.datetime() lastHour = currHour np[2] = Black np.write() hourChanged = True if currMinute != lastMinute: # displayText(display, 'Min', 1) lastMinute = currMinute minuteChanged = True # ************ # Display time if timeNow[4] < 10: displayTimeNow = '0{0}{2}{1}' else: displayTimeNow = '{0}{2}{1}' if timeNow[5] < 10: displayTimeNow = displayTimeNow.replace('{2}', '0') else: displayTimeNow = displayTimeNow.replace('{2}', '') displayTimeNow = displayTimeNow.replace('{0}', str(timeNow[4])) displayTimeNow = displayTimeNow.replace('{1}', str(timeNow[5])) if displayTimeNow != displayTimeLast: displayTimeLast = displayTimeNow displayText(display, str(displayTimeNow), 0) # ********************* # Display seconds pixel seconds = timeNow[6] if (seconds/2) == round(seconds/2): display.rect(15, 5, 2, 2, 1) else: display.rect(15, 5, 2, 2, 0) # ***************** # Display the graph if initLoop or (currMinute in [1, 16, 31, 46] and minuteChanged): gData = getGraphData() jData = ujson.loads(gData) min = 100 max = 0 gOff = 8 * 8 display.line(gOff, 0, gOff, 7, 1) display.line(gOff, 7, gOff + 32, 7, 1) # Get min and max sample = 0 for column in jData: # print(jData[sample]) if column < min: min = column if column > max: max = column sample += 1 # ****************** # Draw the bar graph sample = 31 for column in jData: bar = round(7 - (7 / (max - min)) * (column - min)) display.line(gOff + sample, 7, gOff + sample, bar, 1) sample -= 1 currentTemp = jData[0] # Print current temp display.text(str(currentTemp), 32, 0, 1) display.show() hourChanged = False minuteChanged = False initLoop = False # print('Loop') time.sleep(0.25)
def receiver(): ap = network.WLAN(network.AP_IF) # ap.active(False) ap.active(True) ap.config(essid='pyb_test', authmode=2, password='******') time.sleep(3) led = Pin(2, Pin.OUT) led.on() #light addr0 = ('192.168.4.1', 8085) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #UDP s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(addr0) s.settimeout(0.5) # #子节点 # s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) # addr1 = ('192.168.4.2', 8080) print("start ap ok.") ### spi = SPI(1, baudrate=1000000, polarity=1, phase=0, sck=Pin(4), mosi=Pin(23)) ss = Pin(5, Pin.OUT) display = max7219.Matrix8x8(spi, ss, 16) display.buffer = b'\x00\x00\x00\x00\x18\x8c\x18\x8c\x00\x00\x00\x00\x18\x8c\x18\x8c\x00\x00\x00\x00\x18\x84\x18\x84\x00\x00\x00\x00\x18\x84\x18\x84\x00\x00\x00\x00\x07\xfc\x07\xfc\x00\x00\x00\x00\x07\xfc\x07\xfc\x00\xc0\x00\xc0\x00\x80\x00\x80\x00\xc0\x00\xc0\x00\x80\x00\x80\x01\xe0\x01\xe0\x00\x80\x00\x80\x01\xe0\x01\xe0\x00\x80\x00\x80\x02\xa0\x02\xa0\x00\x80\x00\x80\x02\xa0\x02\xa0\x00\x80\x00\x80\x04\x90\x04\x90\x00\x80\x00\x80\x04\x90\x04\x90\x00\x80\x00\x80\x0c\x98\x0c\x98\x00\x80\x00\x80\x0c\x98\x0c\x98\x00\x80\x00\x80' display.show() ### temp_status = 0 while 1: #UDP传输 #第一个节点 # s1.sendto(b'\x01', addr1) recv_data1 = None recv_addr1 = None try: while 1: temp1, temp2 = s.recvfrom(1024) recv_data1, recv_addr1 = temp1, temp2 #直至最新 except: pass if recv_data1 != None: print(recv_data1) led.off() #dark time.sleep(1) led.on() #light # s1.sendto(b'\x11',addr1) #发回表示收到 if recv_data1 == b'\x11': #请求变道 #大佬大佬 display.buffer = b'\x01\x00\x08@\x02\x80\x90\x80\x01\x00\x08@\x02\x80\x90\x80\x01\x00\x08@\x02\x80\x11\x84\x01\x00\x08@\x02\x80\x11\x84\x01\x00\x08D\x04@\x12\x98\x01\x00\x08D\x04@\x12\x98\x01\x00\x13\xf4\x04@\x14\xe0\x01\x00\x13\xf4\x04@\x14\xe0\x01\x00\x10H\x08 \x18\x82\x01\x00\x10H\x08 \x18\x82\xff\xfe0P\x10\x10\x10\x82\xff\xfe0P\x10\x10\x10\x82\x01\x007\xfe \x08\x10~\x01\x007\xfe \x08\x10~\x01\x00P@\xc0\x06\x10\x00\x01\x00P@\xc0\x06\x10\x00' display.show() time.sleep(1) #求插个队 display.buffer = b"\x01 \x08\x03@6\\\x01\x00\x00@\x01\x00D\xa0\x01\x10 <\x05 \xe4D\x01\x00|@\x01\x00D\xa0\x01\x00'\xc0\t\x10$D\x02\x80D@\x01\x00D\xa0\x7f\xfc @\x11\x08'\\\x04@H@\x01\x00i\x10\x01\x00\xf8@a\x06$D\x08 H@\x01\x00Q\x10!\x08/\xfe\x01\x00$D\x10\x10P@\x01\x00B\x08\x11\x10 @\x05\x00\xa7\xfc!\x08H@\x01\x00D\x04\t\xa0)@\x02\x00D\x04\xc1\x06H@\x01\x00H\x02" display.show() time.sleep(1) temp_status = 1 elif recv_data1 == b'\x00': #只感谢一次 if temp_status == 1: temp_status = 0 #感谢大佬 display.buffer = b"\x00(\x01\x08(\x92$\xa8\x01\x00\x08@\x02\x80\x90\x80\x00$B\x08O\xaa/\xa8\x01\x00\x08@\x02\x80\x11\x84?\xfe'\x88@F!\x88\x01\x00\x08D\x04@\x12\x98 $\x88\x80\x82*\x88\x01\x00\x13\xf4\x04@\x14\xe0/\xa4\x07\xbe\x01\x004\x88\x01\x00\x10H\x08 \x18\x82 $\x04\x88H\x84(\x88\xff\xfe0P\x10\x10\x10\x82/\xa8\xe7\x88H\x12\x02\xa8\x01\x007\xfe \x08\x10~(\x98$\xc8\x87\xf2\x01\x10\x01\x00P@\xc0\x06\x10\x00" display.show() time.sleep(1) #祝您每天 display.buffer = b' \x00\t\x00T\x90\x14D\x10\x00\x00\x00\xff\xfe\x02\x80\x13\xfc\t\x00\x94\x90\x11@\x1f\xfc?\xf8 \x10\x02\x80\x12\x04\x11\xfc\x10\x90\x10\x80 \x00\x01\x00"\x10\x04@\xfa\x042\x04\x11\x12\x02\x00 \x00\x01\x00!\x10\x04@\n\x04TH\x11\x12Q\x04_\xf0\x01\x00?\xfc\x08 \x12\x04\x99P\x12\x12Q\x12\x90\x10\x01\x00\x00\x10\x10\x10\x13\xfc\x11H\x14\x0e\x90\x12\x12\x10\xff\xfe\x00\xa0 \x088\x90\x12D\x18\x00\x0f\xf0\x11\x10\x01\x00\x00@\xc0\x06' display.show() time.sleep(0.5) #万事顺利 display.buffer = b'\x00\x00\x01\x00\x04\x10?\xf8\x04\x00\x01\x04U$\x16$\x00\x00\x01\x00\x08\x10\x01\x08E\xfe\x07\x84U$\x15$\xff\xfe\xff\xfe\x08\x10\xff\xfeT |\x04U$$\xa4\x04\x00\x01\x00\x10\x10\x01\x08T@\x04$UD$$\x04\x00?\xf8\x10\x10?\xf8U\xfc\x04$TPD\x04\x04\x00!\x08 \x10\x01\x00U\x04\x04$T\x88\x84\x04\x07\xf0?\xf8@\xa0\x05\x00U$\xff\xa4\x85\x04\x04\x14\x04\x10\x01\x00\x80@\x02\x00U$\x0c$\x06\x02\x04\x08' display.show() time.sleep(1) else: #平时状态 #可根据time.time()循环播放,也可根据串口屏回传信息判断动图结束再播放 #fig display.buffer = b'\x00\x00\x00\x00\x18\x8c\x18\x8c\x00\x00\x00\x00\x18\x8c\x18\x8c\x00\x00\x00\x00\x18\x84\x18\x84\x00\x00\x00\x00\x18\x84\x18\x84\x00\x00\x00\x00\x07\xfc\x07\xfc\x00\x00\x00\x00\x07\xfc\x07\xfc\x00\xc0\x00\xc0\x00\x80\x00\x80\x00\xc0\x00\xc0\x00\x80\x00\x80\x01\xe0\x01\xe0\x00\x80\x00\x80\x01\xe0\x01\xe0\x00\x80\x00\x80\x02\xa0\x02\xa0\x00\x80\x00\x80\x02\xa0\x02\xa0\x00\x80\x00\x80\x04\x90\x04\x90\x00\x80\x00\x80\x04\x90\x04\x90\x00\x80\x00\x80\x0c\x98\x0c\x98\x00\x80\x00\x80\x0c\x98\x0c\x98\x00\x80\x00\x80' display.show() time.sleep_ms(100)
def dp(self): hspi = SPI(1, baudrate=10000000, polarity=0, phase=0) self.display = max7219.Matrix8x8(hspi,Pin(5),4)
import max7219 from machine import Pin, SPI, freq tile = 1 freq(160000000) spi = SPI(1, baudrate=10000000, polarity=0, phase=0) display = max7219.Matrix8x8(spi, Pin(2), tile) display.brightness(10) display.fill(0) display.show() display.scroll_left(" 3 2 1 Welcome and Have Fun!!")
import max7219 from machine import Pin from machine import SPI import time spi = SPI(-1, baudrate=10000000, miso=Pin(10), mosi=Pin(12), sck=Pin(11)) display = max7219.Matrix8x8(spi, 1) while True: afficher(smile) time.sleep(1) afficher(triste) time.sleep(1)
import max7219 from machine import Pin, SPI import utime spi = SPI(sck=Pin.board.CLK0, miso=Pin.board.MISO, mosi=Pin.board.MOSI) ss = Pin(Pin.board.P9, Pin.OUT) display = max7219.Matrix8x8(spi, ss, 5) #creat virtual disaply five 8x8 matrixs while True: display.text('54321', 0, 0, 1) display.show() for i in range(41): display.scroll(1, 0) display.show() utime.sleep_ms(200) """ display.fill(0) display.show() display.pixel(0,0,1) display.pixel(1,1,1) display.hline(0,4,8,1) display.vline(4,0,8,1) display.line(8, 0, 16, 8, 1) display.rect(17,1,6,6,1) display.fill_rect(25,1,6,6,1) display.show()
# setup (h)SPI for MAX7219 with dot LED matrix #if False: if True: # hardware SPI (boudrate up to 80 MHz, real about from 1 kHz to 13.25 MHz) spi = SPI(1, baudrate=10000000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12)) else: # software SPI bus on the given pins (baudrate from 1 kHz to 500 kHz) # polarity is the idle state of SCK # phase=0 means sample on the first edge of SCK, phase=1 means the second spi = SPI(-1, baudrate=500000, polarity=0, phase=0, sck=Pin(14), mosi=Pin(13), miso=Pin(12)) #spi.init(baudrate=100000) # set the baudrate CS = 27 # CS on D27 (GPIO-27) NUM = 4 # number of 8x8 dot matrix blocks display = max7219.Matrix8x8(spi, Pin(CS, Pin.OUT), NUM) display.brightness(1) # [0..15] display.fill(0) display.show() """ # put text (4x6 font) on frame buffer def put_text(fbuf, text, x=0, y=0): for uchr in text: sym = FONT[ord(uchr)] for i in range(4): for j in range(6): fbuf.pixel(x + i, y + j, 1 if (sym[i] & (0x20 >> j)) else 0) x += 4 """
import max7219 import time from machine import Pin, SPI spi = SPI(1, baudrate=10000000, polarity=0, phase=0) display = max7219.Matrix8x8(spi, Pin(15), 12) display.fill(0) display.show() time.sleep(2) display.pixel(0, 0, 1) display.pixel(1, 1, 1) display.hline(0, 4, 8, 1) display.vline(4, 0, 8, 1) display.line(8, 0, 16, 8, 1) display.rect(17, 1, 6, 6, 1) display.fill_rect(25, 1, 6, 6, 1) display.show() time.sleep(2) display.fill(0) display.text('dead', 0, 0, 1) display.text('beef', 32, 0, 1) display.text('jell', 64, 0, 1) display.show() time.sleep(2) display.fill(0) display.text('12345678', 0, 0, 1)
CS SPI0 CSn GP5 7 CLK SPI0 SCK GP6 9 DIN SPI0 TX GP7 10 ''' import max7219 from machine import Pin, SPI from time import sleep num_display = 4 cs_pin = Pin(5, Pin.OUT) spi = SPI(0) display = max7219.Matrix8x8(spi, cs_pin, num_display) while True: display.fill(0) display.text('1234', 0, 1, 1) display.show() sleep(3) display.fill(0) display.text('abcd', 0, 1, 1) display.show() sleep(3) display.fill(0) display.text('WXYZ', 0, 1, 1) display.show()
import max7219 from machine import Pin, SPI import time spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(21), mosi=Pin(16)) ss = Pin(17, Pin.OUT) display = max7219.Matrix8x8(spi, ss, 1) display.brightness(15) text = "fit2019 " #display.text(text,0,0,1) #display.show() while True: for i in range(len(text)): display = max7219.Matrix8x8(spi, ss, i + 1) display.text(text, 0, 0, 1) time.sleep(1) display.show()
def setup(): global display spi = SPI(1, baudrate=10000000, polarity=0, phase=0) display = max7219.Matrix8x8(spi, Pin(15), 4) display.brightness(0) display.fill(0)