所有分类
主题 主题
平台 平台
我的工作台
userHead
注册时间 [[userInfo.create_time]]
创造力 [[userInfo.creativity]]
[[userInfo.remark]]
[[d.project_title]]
articleThumb
[[d.material_name]]
timelineThumb
进入工作台
折叠
所有分类 我的工作台
展开

【PinPong Board】来自母亲节的祝福

hmilycheng hmilycheng 2021-05-09 01:32:05
材料清单 材料清单
1x
PinPong Board

慈母手中线,游子身上衣。

临行密密缝,意恐迟迟归。

谁言寸草心,报得三春晖。

projectImage

母爱是一缕阳光,让你的心灵即使在寒冷的冬天也能感到温暖如春;母爱是一泓清泉,让你的情感即使蒙上岁月的风尘依然纯洁明净。

今天正值母亲节,我用PinPong Board送上对天下妈妈们最真挚的祝福!妈妈们节日快乐!

步骤1 步骤1
连接wifi
代码 代码
	                    					from pinpong.board import Board,Pin,WIFI
from dfrobot_ssd1306 import SSD1306,SSD1306_I2C #导入ssd1306库
import math
import time
import ntplib
Board("uno").begin()  #初始化,选择板型和端口号,不输入端口号则进行自动识别
oled=SSD1306_I2C(width=128, height=64) #初始化屏幕,传入屏幕像素点数
oled.fill(0)
obj = WIFI()
ssid = "ssid"                      #wifi名
password = "password"                    #wifi密码
obj.set_ssid(ssid)                          #设置wifi名
obj.set_password(password)                  #设置wifi密码
obj.connect_wifi()                          #开始连接
print("Waiting for WIFI connection...")
time.sleep(5)
while True:
  ip,port = obj.get_ip_port()
  if ip != None:
    print("ip: {} port: {}".format(ip, port))
    break
  time.sleep(1)
ip = "ip:" + str(ip)
port = "port:"+str(port)
oled.text(ip,0,10) #指定位置显示文字
oled.text(port,0,30)
oled.show()  #显示生效
	                    				
步骤2 步骤2
通过NTP获得网络时间
代码 代码
	                    					import ntplib
c = ntplib.NTPClient()
response = c.request('ntp1.aliyun.com', version=3)     
ts = response.tx_time
_date = time.strftime('%Y-%m-%d',time.localtime(ts)) 
_time = time.strftime('%X',time.localtime(ts))
print(_date[0:4]+"年"+_date[5:7]+"月"+_date[8:10]+"日")
print(_time)

	                    				
步骤3 步骤3
准备字库文件font

由于dfrobot_ssd1306库不带字库文件,为了正常显示中文,需要准备字库文件font.py,如下代码所示:

代码 代码
	                    					byte = {

0xe5b9b4:
    [0x10,0x10,0x1F,0x20,0x20,0x40,0x1F,0x10,0x10,0x10,0xFF,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0xFC,0x80,0x80,0x80,0xF8,0x80,0x80,0x80,0xFE,0x80,0x80,0x80,0x80,0x80],#年
0xe69c88:
    [0x00,0x1F,0x10,0x10,0x10,0x1F,0x10,0x10,0x10,0x1F,0x10,0x10,0x20,0x20,0x40,0x80,
    0x00,0xF8,0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x08,0x28,0x10],#月
0xe697a5:
    [0x00,0x1F,0x10,0x10,0x10,0x10,0x10,0x1F,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0x10,
    0x00,0xF0,0x10,0x10,0x10,0x10,0x10,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0xF0,0x10],#日
0xe6989f:
    [0x00,0x1F,0x10,0x1F,0x10,0x1F,0x01,0x11,0x1F,0x21,0x41,0x1F,0x01,0x01,0x7F,0x00,
    0x00,0xF0,0x10,0xF0,0x10,0xF0,0x00,0x00,0xF8,0x00,0x00,0xF0,0x00,0x00,0xFC,0x00],#星
0xe69c9f:
    [0x22,0x22,0x7F,0x22,0x22,0x3E,0x22,0x22,0x3E,0x22,0x22,0xFF,0x04,0x22,0x41,0x82,
    0x00,0x7C,0x44,0x44,0x44,0x7C,0x44,0x44,0x44,0x7C,0x44,0x44,0x84,0x84,0x14,0x08],#期
0xe7a59d:
    [0x20,0x13,0x12,0xFA,0x0A,0x12,0x13,0x38,0x54,0x94,0x10,0x11,0x11,0x12,0x14,0x18,
    0x00,0xFC,0x04,0x04,0x04,0x04,0xFC,0x90,0x90,0x90,0x90,0x12,0x12,0x12,0x0E,0x00],#祝
0xe5a688:
    [0x10,0x13,0x10,0x10,0xFD,0x25,0x25,0x25,0x24,0x48,0x28,0x13,0x28,0x44,0x84,0x00,
    0x00,0xF0,0x10,0x10,0x10,0x10,0x10,0xFC,0x04,0x04,0x04,0xF4,0x04,0x04,0x28,0x10],#妈
0xe4bbac:
    [0x09,0x08,0x08,0x12,0x12,0x32,0x32,0x52,0x92,0x12,0x12,0x12,0x12,0x12,0x12,0x12,
    0x00,0x80,0xBC,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x14,0x08],#们
0xe6af8d:
    [0x00,0x1F,0x10,0x12,0x11,0x11,0xFF,0x20,0x22,0x21,0x21,0x3F,0x00,0x00,0x00,0x00,
    0x00,0xF0,0x10,0x10,0x10,0x10,0xFE,0x10,0x10,0x10,0x10,0xFC,0x10,0x10,0xA0,0x40],#母
0xe4bab2:
    [0x02,0x01,0x3F,0x00,0x08,0x04,0xFF,0x01,0x01,0x7F,0x01,0x09,0x11,0x21,0x45,0x02,
    0x00,0x00,0xF8,0x00,0x20,0x40,0xFE,0x00,0x00,0xFC,0x00,0x20,0x10,0x08,0x04,0x00],#亲
0xe88a82:
    [0x08,0x08,0xFF,0x08,0x08,0x00,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,
    0x20,0x20,0xFE,0x20,0x20,0x00,0xF8,0x08,0x08,0x08,0x08,0x50,0x20,0x00,0x00,0x00],#节
0xe5bfab:
    [0x10,0x10,0x10,0x13,0x18,0x54,0x50,0x50,0x97,0x10,0x10,0x10,0x11,0x11,0x12,0x14,
    0x40,0x40,0x40,0xF8,0x48,0x48,0x48,0x48,0xFE,0x40,0xA0,0xA0,0x10,0x10,0x08,0x06],#快
0xe4b990:
    [0x00,0x00,0x1F,0x10,0x11,0x21,0x21,0x3F,0x01,0x09,0x09,0x11,0x21,0x41,0x05,0x02,
    0x20,0xF0,0x00,0x00,0x00,0x00,0x00,0xFC,0x00,0x20,0x10,0x08,0x04,0x04,0x00,0x00]#乐
}
	                    				
步骤4 步骤4
OLED显示时间及祝福语
代码 代码
	                    					oled.fill(0)
oled.text(str(_date),22,5)
oled.text(str(_time),30,25)
oled.textch('祝妈妈们节日快乐',0,6)
oled.show()
	                    				
projectImage

以下是main.py完整代码:

代码 代码
	                    					from pinpong.board import Board,Pin,WIFI
from dfrobot_ssd1306 import SSD1306,SSD1306_I2C #导入ssd1306库
import math
import time
import ntplib
Board("uno").begin()  #初始化,选择板型和端口号,不输入端口号则进行自动识别
oled=SSD1306_I2C(width=128, height=64) #初始化屏幕,传入屏幕像素点数
oled.fill(0)
obj = WIFI()
ssid = "ssid"                      #wifi名
password = "password"                    #wifi密码
obj.set_ssid(ssid)                          #设置wifi名
obj.set_password(password)                  #设置wifi密码
obj.connect_wifi()                          #开始连接
print("Waiting for WIFI connection...")
time.sleep(5)
while True:
  ip,port = obj.get_ip_port()
  if ip != None:
    print("ip: {} port: {}".format(ip, port))
    break
  time.sleep(1)

ip = "ip:" + str(ip)
port = "port:"+str(port)
oled.text(ip,0,10) #指定位置显示文字
oled.text(port,0,30)
oled.show()  #显示生效
while True:
    c = ntplib.NTPClient()
    response = c.request('ntp1.aliyun.com', version=3)     
    ts = response.tx_time
    _date = time.strftime('%Y-%m-%d',time.localtime(ts)) 
    _time = time.strftime('%X',time.localtime(ts))
    print(_date[0:4]+"年"+_date[5:7]+"月"+_date[8:10]+"日")
    print(_time)
    oled.fill(0)
    oled.text(str(_date),22,5)
    oled.text(str(_time),30,25)
    oled.textch('祝妈妈们节日快乐',0,6)
    oled.show()
	                    				
Makelog作者原创文章,未经授权禁止转载。
0
1
评论
[[c.user_name]] [[c.create_time]]
[[c.parent_comment.count]]
|
[[c.comment_content]]