def __init__(self): spi = SPI(2, sck=Pin(18), mosi=Pin(23), miso=Pin(19),baudrate=14500000) self.display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) # self.display("连接MQTT服务器...") self.mqtt = network.mqtt("otv", "mqtt://t.hsxsix.com", user="******", password="******", cleansession=True, connected_cb=self.conncb, disconnected_cb=self.disconncb, subscribed_cb=self.subscb, published_cb=self.pubcb, data_cb=self.datacb) self.weather_data = {} self.weather_api = 'http://118.24.144.127/weather/v1?city={}&node=micropython_ssd1351' self.weather_tm = Timer(2) self.weather_tm.init(period=1000*60*20, mode=self.weather_tm.PERIODIC, callback=self.update_weather)
def test(): """Test code.""" # Baud rate of 14500000 seems about the max spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) x, y = 0, 0 angle = 0.0 # Loop all angles from 0 to 2 * PI radians while angle < PI2: # Calculate x, y from a vector with known length and angle x = int(CENTER_X * sin(angle) + HALF_WIDTH) y = int(CENTER_Y * cos(angle) + HALF_HEIGHT) color = color565(*hsv_to_rgb(angle / PI2, 1, 1)) display.draw_line(x, y, CENTER_X, CENTER_Y, color) angle += ANGLE_STEP_SIZE sleep(5) for r in range(CENTER_X, 0, -1): color = color565(*hsv_to_rgb(r / HALF_WIDTH, 1, 1)) display.fill_circle(CENTER_X, CENTER_Y, r, color) sleep(9) display.cleanup()
def test(): """CircuitPython Text, Shape & Sprite""" if implementation.name != 'circuitpython': print() print('This demo is for CircuitPython only!') exit() try: # Configuratoin for CS and DC pins: cs_pin = DigitalInOut(board.P0_15) dc_pin = DigitalInOut(board.P0_17) rst_pin = DigitalInOut(board.P0_20) # Setup SPI bus using hardware SPI: spi = SPI(clock=board.P0_24, MOSI=board.P0_22) # Create the SSD1351 display: display = Display(spi, dc=dc_pin, cs=cs_pin, rst=rst_pin) display.clear() # Load Fixed Font fixed = XglcdFont('fonts/FixedFont5x8.c', 5, 8, letter_count=96) # Title WIDTH = 128 text = 'CircuitPython Demo' # Measure text and center length = fixed.measure_text(text) x = int((WIDTH / 2) - (length / 2)) display.draw_text(x, 6, text, fixed, color565(255, 255, 0)) # Draw title outline display.draw_rectangle(0, 0, 127, 20, color565(0, 255, 0)) # Load sprite logo = BouncingSprite('images/blinka45x48.raw', 45, 48, 128, 128, 1, display) while True: timer = monotonic() logo.update_pos() logo.draw() # Attempt to set framerate to 30 FPS timer_dif = .033333333 - (monotonic() - timer) if timer_dif > 0: sleep(timer_dif) except KeyboardInterrupt: display.cleanup()
def __init__(self): self.button_left = Pin(pd.BUTTON_LEFT, Pin.IN, Pin.PULL_UP) self.button_right = Pin(pd.BUTTON_RIGHT, Pin.IN, Pin.PULL_UP) self.mic = components.Microphone(pd.MIC) self.joystick = components.Joystick(pd.JOYSTICK_X, pd.JOYSTICK_Y) self.joystick_sw = Pin(pd.JOYSTICK_SW, Pin.IN, Pin.PULL_UP) self.encoder = Encoder(pin_clk=pd.ENCODER_CLK, pin_dt=pd.ENCODER_DT, clicks=4) self.encoder_sw = Pin(pd.ENCODER_SW, Pin.IN, Pin.PULL_UP) # self.spi = SPI(2, 2000000, miso=Pin(pd.SPI_MISO), mosi=Pin(pd.SPI_MOSI), sck=Pin(pd.SPI_SCK)) self.spi = SPI(2, baudrate=14500000, miso=Pin(pd.SPI_MISO), mosi=Pin(pd.SPI_MOSI), sck=Pin(pd.SPI_SCK)) self.display = Display(self.spi, rst=Pin(pd.SSD1351_RST), dc=Pin(pd.SSD1351_DC), cs=Pin(pd.SSD1351_CS)) self.beeper = PWM(Pin(pd.BUZZER), freq=300, duty=0) self.i2c = I2C(scl=Pin(pd.I2C_SCL), sda=Pin(pd.I2C_SDA))
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(4), cs=Pin(5), rst=Pin(21)) while 1: display.draw_image('1.raw', 0, 32, 128, 96) sleep(5) display.draw_image('2.raw', 0, 32, 128, 96) sleep(5) display.cleanup()
def draw_text(self, x, y, text, font, color, background=0, landscape=False, spacing=1): max_length = (self.width - x + spacing) // (font.width + spacing) text = text[0:min(max_length, len(text))] Display.draw_text(self, x, y, text, font, color, background=background, landscape=landscape, spacing=spacing)
def test(): """Bouncing box.""" try: # Baud rate of 14500000 seems about the max spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.clear() colors = [ color565(255, 0, 0), color565(0, 255, 0), color565(0, 0, 255), color565(255, 255, 0), color565(0, 255, 255), color565(255, 0, 255) ] sizes = [12, 11, 10, 9, 8, 7] boxes = [Box(128, 128, sizes[i], display, colors[i]) for i in range(6)] while True: timer = ticks_us() for b in boxes: b.update_pos() b.draw() # Attempt to set framerate to 30 FPS timer_dif = 33333 - ticks_diff(ticks_us(), timer) if timer_dif > 0: sleep_us(timer_dif) except KeyboardInterrupt: display.cleanup()
def test(): """Test code.""" # Baud rate of 14500000 seems about the max spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) c = 0 for x in range(0, 128, 16): for y in range(0, 128, 16): color = color565(*hsv_to_rgb(c / 64, 1, 1)) display.fill_circle(x + 7, y + 7, 7, color) c += 1 sleep(9) display.cleanup()
def test(): """Test code.""" # Baud rate of 14500000 seems about the max spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) # Build color list from all upper case constants (lazy approach) colors = [getattr(modules[__name__], name) for name in dir( modules[__name__]) if name.isupper() and name is not 'SPI'] colors.sort() c = 0 for x in range(1, 126, 25): for y in range(1, 126, 25): display.fill_rectangle(x, y, 25, 25, colors[c]) c += 1 sleep(9) display.cleanup()
def test(): """Bouncing sprite.""" try: # Baud rate of 14500000 seems about the max spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.clear() # Load sprite logo = BouncingSprite('images/Python41x49.raw', 41, 49, 128, 128, 1, display) while True: timer = ticks_us() logo.update_pos() logo.draw() # Attempt to set framerate to 30 FPS timer_dif = 33333 - ticks_diff(ticks_us(), timer) if timer_dif > 0: sleep_us(timer_dif) except KeyboardInterrupt: display.cleanup()
def main(): """Initialize display.""" # Baud rate of 14500000 seems about the max # spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) # display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) # use Wifiboy screen pins spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) # Draw background image display.draw_image('images/Arkanoid_Border128x118.raw', 0, 10, 128, 118) # Initialize ADC on VP pin 36 adc = ADC(Pin(36)) # Set attenuation 0-2V (Will use resistor to limit pot to 2V). adc.atten(ADC.ATTN_6DB) # Seed random numbers seed(ticks_us()) # Generate bricks MAX_LEVEL = const(9) level = 1 bricks = load_level(level, display) # Initialize paddle paddle = Paddle(display) # Initialize score score = Score(display) # Initialize balls balls = [] # Add first ball balls.append(Ball(59, 111, -2, -1, display, frozen=True)) # Initialize lives lives = [] for i in range(1, 3): lives.append(Life(i, display)) # Initialize power-ups powerups = [] try: while True: timer = ticks_us() # Set paddle position to ADC spinner (scale 6 - 98) paddle.h_position(adc.read() // 44 + 5) # Handle balls score_points = 0 for ball in balls: # Position ball.set_position(paddle.x, paddle.y, paddle.x2, paddle.center) # Check for collision with bricks if not frozen if not ball.frozen: prior_collision = False ball_x = ball.x ball_y = ball.y ball_x2 = ball.x2 ball_y2 = ball.y2 ball_center_x = ball.x + ((ball.x2 + 1 - ball.x) // 2) ball_center_y = ball.y + ((ball.y2 + 1 - ball.y) // 2) # Check for hits for brick in bricks: if (ball_x2 >= brick.x and ball_x <= brick.x2 and ball_y2 >= brick.y and ball_y <= brick.y2): # Hit if not prior_collision: ball.x_speed, ball.y_speed = brick.bounce( ball.x, ball.y, ball.x2, ball.y2, ball.x_speed, ball.y_speed, ball_center_x, ball_center_y) prior_collision = True score_points += 1 brick.clear() bricks.remove(brick) # Generate random power-ups if score_points > 0 and randint(1, 20) == 7: powerups.append(Powerup(ball.x, 64, display)) # Check for missed if ball.y2 > display.height - 3: ball.clear_previous() balls.remove(ball) if not balls: # Clear powerups powerups.clear() # Lose life if last ball on screen if len(lives) == 0: score.game_over() else: # Subtract Life lives.pop().clear() # Add ball balls.append( Ball(59, 112, 2, -3, display, frozen=True)) else: # Draw ball ball.draw() # Update score if changed if score_points: score.increment(score_points) # Handle power-ups for powerup in powerups: powerup.set_position(paddle.x, paddle.y, paddle.x2, paddle.center) powerup.draw() if powerup.collected: # Power-up collected powerup.clear() # Add ball balls.append( Ball(powerup.x, 112, 2, -1, display, frozen=False)) powerups.remove(powerup) elif powerup.y2 > display.height - 3: # Power-up missed powerup.clear() powerups.remove(powerup) # Check for level completion if not bricks: for ball in balls: ball.clear() balls.clear() for powerup in powerups: powerup.clear() powerups.clear() level += 1 if level > MAX_LEVEL: level = 1 bricks = load_level(level, display) balls.append(Ball(59, 111, -2, -1, display, frozen=True)) # Attempt to set framerate to 30 FPS timer_dif = 33333 - ticks_diff(ticks_us(), timer) if timer_dif > 0: sleep_us(timer_dif) except KeyboardInterrupt: display.cleanup()
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.contrast(0) display.draw_image('images/MicroPython128x128.raw', 0, 0, 128, 128) fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8) contrast_range = list(range(1, 16)) + list(reversed(range(15))) for c in contrast_range: display.contrast(c) display.draw_text(30, 120, 'contrast: {0:02d}'.format(c), fixed_font, color565(255, 255, 255)) sleep(1) display.cleanup()
color = color565(255, 255, 0) if water_level < 20: color = color565(255, 0, 0) if water_level > 0: display.fill_hrect(1, 53, water_level, 18, color) display.fill_hrect(water_level + 1, 53, 121 - water_level, 18, color565(0, 0, 0)) display.draw_text(37, 40, str(water_level) + '/' + str(MAX_WATER) + ' ', bally, color565(255, 255, 255)) if spi is None: spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.draw_image('MicroPython128x128.raw', 0, 0, 128, 128) sleep(1) display.clear() bally = XglcdFont('Bally7x9.c', 7, 9) display.draw_text(0, 0, 'Diesel:', bally, color565(255, 255, 255)) display.draw_text(0, 40, 'Vann:', bally, color565(255, 255, 255)) display.draw_text(0, 80, 'Septik:', bally, color565(255, 255, 255)) display.draw_rectangle(0, 12, 120, 20, color565(255, 255, 255)) display.draw_rectangle(0, 52, 120, 20, color565(255, 255, 255)) display.draw_rectangle(0, 92, 120, 20, color565(255, 255, 255)) adc = ADC(Pin(35)) adc.atten(adc.ATTN_11DB) #normalized to 3.3v
from machine import Pin, SPI from ssd1351 import Display, color565 from bitmap_font import BitmapFont s = "0x10,0x00,0x11,0xFC,0x10,0x04,0x10,0x08,0xFC,0x10,0x24,0x20,0x24,0x24,0x27,0xFE,0x24,0x20,0x44,0x20,0x28,0x20,0x10,0x20,0x28,0x20,0x44,0x20,0x84,0xA0,0x00,0x40" spi = SPI(2, sck=Pin(18), mosi=Pin(23), miso=Pin(19), baudrate=14500000) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) while True: s = input("please input:") arcadepix = BitmapFont(s, 16, 16) display.draw_bitmap(32, 64, arcadepix, color565(100, 100, 100)) # buf, w, h = arcadepix.get_buf(color) # print(w,h,buf) # arcadepix = XglcdFont('', 9, 11) # buf, w, h = arcadepix.get_letter('A',color) # print(w,h,buf)
def test(): """Test code.""" # Baud rate of 14500000 seems about the max spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) print('spi started') display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) print('display started') display.clear(color565(64, 0, 255)) sleep(1) display.clear() display.draw_hline(10, 127, 63, color565(255, 0, 255)) sleep(1) display.draw_vline(10, 0, 127, color565(0, 255, 255)) sleep(1) display.fill_hrect(23, 50, 30, 75, color565(255, 255, 255)) sleep(1) display.draw_hline(0, 0, 127, color565(255, 0, 0)) sleep(1) display.draw_line(127, 0, 64, 127, color565(255, 255, 0)) sleep(2) display.clear() coords = [[0, 63], [78, 80], [122, 92], [50, 50], [78, 15], [0, 63]] display.draw_lines(coords, color565(0, 255, 255)) sleep(1) display.clear() display.fill_polygon(7, 63, 63, 50, color565(0, 255, 0)) sleep(1) display.fill_rectangle(0, 0, 15, 127, color565(255, 0, 0)) sleep(1) display.clear() display.fill_rectangle(0, 0, 63, 63, color565(128, 128, 255)) sleep(1) display.draw_rectangle(0, 64, 63, 63, color565(255, 0, 255)) sleep(1) display.fill_rectangle(64, 0, 63, 63, color565(128, 0, 255)) sleep(1) display.draw_polygon(3, 96, 96, 30, color565(0, 64, 255), rotate=15) sleep(3) display.clear() display.fill_circle(32, 32, 30, color565(0, 255, 0)) sleep(1) display.draw_circle(32, 96, 30, color565(0, 0, 255)) sleep(1) display.fill_ellipse(96, 32, 30, 16, color565(255, 0, 0)) sleep(1) display.draw_ellipse(96, 96, 16, 30, color565(255, 255, 0)) sleep(5) display.cleanup()
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.draw_image('images/Tabby128x128.raw', 0, 0, 128, 128) print("Loading fonts, please wait.") fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8) unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) print("Fonts loaded.") display.draw_text(0, 0, 'Not transparent', fixed_font, color565(255, 0, 255)) display.draw_text(0, 80, 'Transparent', unispace, color565(0, 128, 255), spacing=0, transparent=True) display.draw_text(0, 103, 'Background', unispace, color565(0, 128, 255), color565(255, 255, 255), spacing=0) display.draw_text(103, 20, 'Test', unispace, color565(0, 255, 128), landscape=True, spacing=2, transparent=True) display.draw_text(0, 20, 'Test', unispace, color565(128, 255, 0), landscape=True) sleep(9) display.cleanup()
from adafruit_ble.uart import UARTServer from adafruit_bluefruit_connect.packet import Packet from adafruit_bluefruit_connect.button_packet import ButtonPacket from random import randint, seed from time import monotonic, sleep # Configuration for CS, DC and Reset pins (Feather nRF52840 Express): cs_pin = DigitalInOut(board.D11) dc_pin = DigitalInOut(board.D10) rst_pin = DigitalInOut(board.D9) # Setup SPI bus using hardware SPI: spi = SPI(clock=board.SCK, MOSI=board.MOSI) # Create the SSD1351 display: display = Display(spi, dc=dc_pin, cs=cs_pin, rst=rst_pin) display.clear() display.contrast(5) NORTH = const(0) EAST = const(1) SOUTH = const(2) WEST = const(3) UP = ButtonPacket.UP DOWN = ButtonPacket.DOWN LEFT = ButtonPacket.LEFT RIGHT = ButtonPacket.RIGHT BORDER_WIDTH = const(2) WALL_HORIZ_LENGTH = const(27) WALL_VERT_LENGTH = const(44) START_ROOM_X = const(5)
class OTV(): def __init__(self): spi = SPI(2, sck=Pin(18), mosi=Pin(23), miso=Pin(19),baudrate=14500000) self.display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) # self.display("连接MQTT服务器...") self.mqtt = network.mqtt("otv", "mqtt://t.hsxsix.com", user="******", password="******", cleansession=True, connected_cb=self.conncb, disconnected_cb=self.disconncb, subscribed_cb=self.subscb, published_cb=self.pubcb, data_cb=self.datacb) self.weather_data = {} self.weather_api = 'http://118.24.144.127/weather/v1?city={}&node=micropython_ssd1351' self.weather_tm = Timer(2) self.weather_tm.init(period=1000*60*20, mode=self.weather_tm.PERIODIC, callback=self.update_weather) def publish(self, msg): self.mqtt.publish('otv', 'Hi from Micropython') def conncb(self, task): # self.dispaly("连接MQTT成功") print("[{}] Connected".format(task)) self.mqtt.subscribe('otv') def disconncb(self, task): print("[{}] Disconnected".format(task)) def subscb(self, task): print("[{}] Subscribed".format(task)) def pubcb(self, pub): print("[{}] Published: {}".format(pub[0], pub[1])) def datacb(self, msg): ''' data format: "tv_id|image url|XX|XX|XX" ''' _, image_url, image_size, position = msg[2].split('|') print("Received a task to show image:\nimage url:{},\nimage size:{}".format(image_url,image_size)) # self.display.draw_image("收到文件,正在下载。。。") download_image = self.http_get(image_url) w,h = image_size.split(',') x,y = position.split(',') if download_image: self.display.clear() self.display.draw_image(download_image, int(x), int(y), int(w), int(h)) def update_weather(self, timer): # self.display("update weather data。。。") self.http_get(self.weather_api, types='text', file_name='weather.txt') with open(weather_file, 'r') as f: self.weather_data = json.loads(f.read()) def show_today_weather(self): if self.weather_data['code'] == 'ok': today_weather = self.weather_data['0']['weather_code'] current_temp = self.weather_data['0']['current_temp'] current_weather = self.weather_data['0']['current_weather'] date = self.weather_data['0']['date'] temp = self.weather_data['0']['temp'] today_aqi = self.weather_data['0']['aqi'] # self.display.draw_image('bg.raw',0,32,128,96) self.display.draw_image('{}.raw'.format(today_weather),5,37,50,50) i=0 for char in current_weather: start_x=50+int((78-15*len(current_weather))/2)+15*i self.display.draw_bitarray(w_char, start_x,42,15,16) i+=1 i=0 for t_char in temp: start_x =50+int((78-9*len(current_weather))/2)+9*i self.display.draw_bitarray(w_char, start_x,64,9,16) i+=1 x = 9 if len(today_aqi)==9 else 5 for char in today_aqi: if len(char) > 100: self.display.draw_bitarray(w_char, x,92,15,16) x = x+15 else: self.display.draw_bitarray(w_char, x,92,9,16) x = x+9 # for char in date: # self.display.draw_bitarray(w_char, 0,32,9,16) # for char in current_temp: # self.display.draw_bitarray(w_char, 0,32,9,16) else: pass # self.display.draw_image("weather data error!") def show_three_day_weather(self): for day in ('1','2','3'): weather = self.weather_data[day]['weather_code'] temp = self.weather_data[day]['temp'] date = self.weather_data[day]['date'] aqi = self.weather_data[day]['aqi'] def http_get(self, url, types='image', file_name=None): download = None try: proto, dummy, host, path = url.split("/", 3) except ValueError: proto, dummy, host = url.split("/", 2) path = "" if proto == "http:": port = 80 else: raise ValueError("Unsupported protocol: " + proto) if ":" in host: host, port = host.split(":", 1) port = int(port) addr = socket.getaddrinfo(host, port)[0][-1] if not file_name: file_name = path.split('/')[-1] s = socket.socket() s.connect(addr) s.send(bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8')) while True: data = s.readline() if not data or data == b"\r\n": print(data) break if types == 'image': with open (file_name, 'wb') as f: while True: data = s.recv(512) if data: f.write(data) else: download = file_name break else: with open(file_name, 'w') as f: while True: data = s.recv(512) if data: f.write(data) else: download = file_name break s.close() return download def start(self): self.mqtt.start()
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.draw_image('images/RaspberryPiWB128x128.raw', 0, 0, 128, 128) sleep(5) display.draw_image('images/MicroPython128x128.raw', 0, 0, 128, 128) sleep(5) display.draw_image('images/Tabby128x128.raw', 0, 0, 128, 128) sleep(5) display.draw_image('images/Tortie128x128.raw', 0, 0, 128, 128) sleep(9) display.cleanup()
def setup_display(): #mosi=sda spi = SPI(2, 14500000, miso=Pin(19), mosi=Pin(18), sck=Pin(5)) display = Display(spi, rst=Pin(26), dc=Pin(25), cs=Pin(4)) return display
def test(): """Scrolling Marquee""" try: # Implementation dependant pin and SPI configuration if implementation.name == 'circuitpython': import board from busio import SPI from digitalio import DigitalInOut cs_pin = DigitalInOut(board.P0_15) dc_pin = DigitalInOut(board.P0_17) rst_pin = DigitalInOut(board.P0_20) spi = SPI(clock=board.P0_24, MOSI=board.P0_22) else: from machine import Pin, SPI cs_pin = Pin(5) dc_pin = Pin(17) rst_pin = Pin(16) spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) # Create the SSD1351 display: display = Display(spi, dc=dc_pin, cs=cs_pin, rst=rst_pin) display.clear() # Draw non-moving circles display.fill_circle(63, 63, 63, color565(27, 72, 156)) display.fill_circle(63, 63, 53, color565(0, 0, 0)) display.fill_circle(63, 63, 43, color565(189, 0, 36)) display.fill_circle(63, 63, 33, color565(0, 0, 0)) # Load Marquee image display.draw_image('images\Rototron128x26.raw', 0, 50, 128, 26) # Set up scrolling display.set_scroll(horiz_offset=1, vert_start_row=50, vert_row_count=26, vert_offset=0, speed=1) display.scroll(True) while True: # Do nothing, scrolling handled by hardware sleep(1) except KeyboardInterrupt: display.cleanup()
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) print("Loading fonts, please wait.") arcadepix = XglcdFont('fonts/ArcadePix9x11.c', 9, 11) bally = XglcdFont('fonts/Bally7x9.c', 7, 9) broadway = XglcdFont('fonts/Broadway17x15.c', 17, 15) espresso_dolce = XglcdFont('fonts/EspressoDolce18x24.c', 18, 24) fixed_font = XglcdFont('fonts/FixedFont5x8.c', 5, 8) neato = XglcdFont('fonts/Neato5x7.c', 5, 7, letter_count=223) robotron = XglcdFont('fonts/Robotron7x11.c', 7, 11) unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24) wendy = XglcdFont('fonts/Wendy7x8.c', 7, 8) print("Fonts loaded.") display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0)) display.draw_text(0, 12, 'Bally 7x9', bally, color565(0, 255, 0)) display.draw_text(0, 23, 'Broadway', broadway, color565(0, 0, 255)) display.draw_text(0, 36, 'Espresso', espresso_dolce, color565(0, 255, 255)) display.draw_text(0, 64, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255)) display.draw_text(0, 76, 'Neato 5x7', neato, color565(255, 255, 0)) display.draw_text(0, 85, 'Robotron 7x11', robotron, color565(255, 255, 255)) display.draw_text(0, 96, 'Unispace', unispace, color565(255, 128, 0)) display.draw_text(0, 120, 'Wendy 7x8', wendy, color565(255, 0, 128)) sleep(9) display.clear() display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0), landscape=True) display.draw_text(12, 0, 'Bally 7x9', bally, color565(0, 255, 0), landscape=True) display.draw_text(23, 0, 'Broadway', broadway, color565(0, 0, 255), landscape=True) display.draw_text(36, 0, 'Espresso', espresso_dolce, color565(0, 255, 255), landscape=True) display.draw_text(64, 0, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255), landscape=True) display.draw_text(76, 0, 'Neato 5x7', neato, color565(255, 255, 0), landscape=True) display.draw_text(85, 0, 'Robotron 7x11', robotron, color565(255, 255, 255), landscape=True) display.draw_text(96, 0, 'Unispace', unispace, color565(255, 128, 0), landscape=True) display.draw_text(120, 0, 'Wendy 7x8', wendy, color565(255, 0, 128), landscape=True) sleep(9) display.clear() display.draw_text(0, 0, 'Arcade Pix 9x11', arcadepix, color565(255, 0, 0), background=color565(0, 255, 255)) display.draw_text(0, 12, 'Bally 7x9', bally, color565(0, 255, 0), background=color565(0, 0, 128)) display.draw_text(0, 23, 'Broadway', broadway, color565(0, 0, 255), background=color565(255, 255, 0)) display.draw_text(0, 36, 'Espresso', espresso_dolce, color565(0, 255, 255), background=color565(255, 0, 0)) display.draw_text(0, 64, 'Fixed Font 5x8', fixed_font, color565(255, 0, 255), background=color565(0, 128, 0)) display.draw_text(0, 76, 'Neato 5x7', neato, color565(255, 255, 0), background=color565(0, 0, 255)) display.draw_text(0, 85, 'Robotron 7x11', robotron, color565(255, 255, 255), background=color565(128, 128, 128)) display.draw_text(0, 96, 'Unispace', unispace, color565(255, 128, 0), background=color565(0, 128, 255)) display.draw_text(0, 120, 'Wendy 7x8', wendy, color565(255, 0, 128), background=color565(255, 255, 255)) sleep(9) display.cleanup()
def test(): """Test code.""" spi = SPI(2, baudrate=14500000, sck=Pin(18), mosi=Pin(23)) display = Display(spi, dc=Pin(17), cs=Pin(5), rst=Pin(16)) display.draw_text8x8(0, 0, 'Built-in', color565(255, 0, 255)) display.draw_text8x8(16, 16, 'MicroPython', color565(255, 255, 0)) display.draw_text8x8(32, 32, '8x8 Font', color565(0, 0, 255)) display.draw_text8x8(63, 120, "Portrait", color565(0, 255, 0)) display.draw_text8x8(0, 56, "Landscape", color565(255, 0, 0), landscape=True) sleep(9) display.cleanup()
import time import network import urequests import ntptime import _thread import ujson from microWebSrv import MicroWebSrv import gc t = time.time() #oled spi = SPI(2, baudrate=14500000, sck=Pin(26), mosi=Pin(27)) display = Display(spi, dc=Pin(33), cs=Pin(25), rst=Pin(32), width=128, height=128) #font导入 robotron = XglcdFont('Robotron13x21.c', 13, 21) robotronm = XglcdFont('Robotron7x11.c', 7, 11) espressodolc = XglcdFont('EspressoDolce18x24.c', 18, 24) fixedfont = XglcdFont('FixedFont5x8.c', 5, 8) def wjson(a, b, c, d, e, f): df = {} df['wifiname'] = a df['wifipassword'] = b df['set_password'] = c