|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
@FishC 代码上续写在oled显示时间
import time,ntptime,network
import random
from machine import Pin, SoftI2C
import ssd1306
i2c = SoftI2C(Pin(9), Pin(8))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
width = 128
height = 64
def wifi_main():
global inif
wifi=network.WLAN(network.STA_IF)
if not wifi.isconnected():
print('wificoming......')
wifi.active(True)
wifi.connect('ZTE_5GCPE_F9FF','12345678')
while not wifi.isconnected():
pass
print('Wifi connection succeeded')
print('network config:', wifi.ifconfig())
wifi_main()
class Snowflake:
def __init__(self):
self.x = random.randint(0, width - 1)
self.y = random.randint(0, height - 1)
self.speed = random.randint(1, 3)
def move(self):
self.y += self.speed
if self.y > height - 1:
self.y = 5
self.x = random.randint(0, width - 1)
def draw(self):
oled.pixel(self.x, self.y, 1)
class Cloud:
def __init__(self):
self.x = random.randint(0, width - 1)
self.y = 3
self.speed = random.randint(1, 3)
self.direction = random.choice([-1, 1])
def move(self):
self.x += self.speed * self.direction
if self.x < 0:
self.x = width - 1
elif self.x >= width:
self.x = 0
def draw(self):
oled.text("*-*-*", self.x, self.y)
oled.text("-*-*-", self.x, self.y+8)
snowflakes = []
clouds = []
for _ in range(50):
snowflakes.append(Snowflake())
for _ in range(5):
clouds.append(Cloud())
while True:
oled.fill(0)
for snowflake in snowflakes:
snowflake.move()
snowflake.draw()
for cloud in clouds:
cloud.move()
cloud.draw()
a = 0.1
h = 32
k = 20
for x in range(-64, 65):
y = a * (x - h) ** 2 + k
oled.pixel(x + 64, int(y), 1)
oled.show()
|
|