【项目介绍】
WiFi功能的开放,对K10的开发项目更丰富了,首先考虑到的是通过wifi获取网络时间。考虑到屏幕显示内容比较单调,就增加了课程表,这样,通过时间就可以知道每天的课程安排。初步想法是全部内容都通过编程来实现,因划线做表和输入课程名称等比较费事,就直接用ps处理成图片来使用。当然,如果用编程来实现,有个简单的办法就是打印一张32*24的表格来辅助定位。
【项目演示】
材料清单
- 行空板K10 X1
【制作过程】
步骤1 PS课程表
利用PS制作课程表,方便对图片进行处理来符合K10的要求。保存:文件——导出——Web格式——预设(PNG24)——W改为320——存储到指定文件夹。然后保存到存储卡插入到K10中。
步骤2 完善表格
因前期已经编程过,所以没在PS时间输入,也是为了练习一下。代码如下:
步骤3 wifi和网络时间设置
通过好多次的验证,修改为此授权服务器才能正确获取数据
步骤4 时间获取设置
为了防止显示抖动,用矩形覆盖(采用刘春晓老师的建议)。为了显示格式一致,编程中设置了数字一位变两位。至于周,因为获取的数字正好和当前周次相差1,所以简单设置了一下。
完整程序如下:
代码
/*!
* MindPlus
* esp32s3bit
*
*/
#include <DFRobot_Iot.h>
#include "unihiker_k10.h"
#include <MPython_NtpTime.h>
// 创建对象
uint8_t screen_dir=1;
UNIHIKER_K10 k10;
DFRobot_Iot myIot;
MPython_NtpTime ntptime;
// 主程序开始
void setup() {
k10.begin();
k10.initScreen(screen_dir);
k10.creatCanvas();
k10.initSDFile();
k10.canvas->canvasDrawImage(0, 30, "S:/2003.png");
k10.canvas->canvasText("电子课程表", 96, 5, 0x0000FF, k10.canvas->eCNAndENFont24, 50, false);
k10.canvas->canvasText("一", 60, 40, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("二", 101, 40, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("三", 143, 40, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("四", 187, 40, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("五", 231, 40, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("时间", 272, 40, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("1", 26, 60, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("2", 26, 80, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("3", 26, 100, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("4", 26, 140, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("5", 26, 160, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("6", 26, 180, 0xFF0000, k10.canvas->eCNAndENFont16, 7, false);
k10.canvas->canvasText("午 休", 140, 122, 0xFF0000, k10.canvas->eCNAndENFont16, 50, false);
k10.canvas->updateCanvas();
myIot.wifiConnect("Hq123456", "Hq123456");
while (!myIot.wifiStatus()) {}
ntptime.setNtpTime(ntptime.UTCEast8_t, "time.windows.com");
}
void loop() {
k10.canvas->canvasRectangle(35, 206, 32, 16, 0xFFFFCC, 0xFFFFFF, true);
k10.canvas->canvasText((String(ntptime.localTime(ntptime.Year))), 35, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
if ((ntptime.localTime(ntptime.Month)<10)) {
k10.canvas->canvasRectangle(80, 206, 16, 16, 0xFFFFCC, 0xFFFFFF, true);
k10.canvas->canvasText((String("0") + String(ntptime.localTime(ntptime.Month))), 80, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
else {
k10.canvas->canvasRectangle(80, 206, 16, 16, 0xFFFFCC, 0xFFFFFF, true);
k10.canvas->canvasText((String(ntptime.localTime(ntptime.Month))), 80, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
if ((ntptime.localTime(ntptime.Date)<10)) {
k10.canvas->canvasRectangle(108, 206, 16, 16, 0xFFFFCC, 0xFFFFFF, true);
k10.canvas->canvasText((String("0") + String(ntptime.localTime(ntptime.Date))), 108, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
else {
k10.canvas->canvasRectangle(108, 206, 16, 16, 0xFFFFCC, 0xFFFFFF, true);
k10.canvas->canvasText((String(ntptime.localTime(ntptime.Date))), 108, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
if ((ntptime.localTime(ntptime.Hour)<10)) {
k10.canvas->canvasRectangle(143, 206, 16, 16, 0xFFFFCC, 0xFFFFCC, true);
k10.canvas->canvasText((String("0") + String(ntptime.localTime(ntptime.Hour))), 143, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
else {
k10.canvas->canvasRectangle(143, 206, 16, 16, 0xFFFFCC, 0xFFFFCC, true);
k10.canvas->canvasText((String(ntptime.localTime(ntptime.Hour))), 143, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
if ((ntptime.localTime(ntptime.Minute)<10)) {
k10.canvas->canvasRectangle(170, 206, 16, 16, 0xFFFFCC, 0xFFFFCC, true);
k10.canvas->canvasText((String("0") + String(ntptime.localTime(ntptime.Minute))), 171, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
else {
k10.canvas->canvasRectangle(170, 206, 16, 16, 0xFFFFCC, 0xFFFFCC, true);
k10.canvas->canvasText((String(ntptime.localTime(ntptime.Minute))), 171, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
if ((ntptime.localTime(ntptime.Second)<10)) {
k10.canvas->canvasRectangle(198, 206, 16, 16, 0xFFFFCC, 0xFFFFCC, true);
k10.canvas->canvasText((String("0") + String(ntptime.localTime(ntptime.Second))), 198, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
else {
k10.canvas->canvasRectangle(198, 206, 16, 16, 0xFFFFCC, 0xFFFFCC, true);
k10.canvas->canvasText((String(ntptime.localTime(ntptime.Second))), 198, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
}
k10.canvas->canvasRectangle(260, 206, 8, 16, 0xFFFFCC, 0xFFFFCC, true);
k10.canvas->canvasText((String((ntptime.localTime(ntptime.Week) - 1))), 260, 206, 0x0000FF, k10.canvas->eCNAndENFont16, 10, false);
k10.canvas->updateCanvas();
delay(1000);
}
【项目总结】
1.项目制作过程中,感谢刘老师多次耐心指导,解决了抖动问题
2.本来想着,通过周的数值而框选当天到课程,最终没有完成效果
附件
评论