基于NodeMcu开发的ESP8266物联网LED灯控制设备,接入SSD1306作为配网以及服务显示功能,后续会增加更多功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.0 KiB

1 year ago
Id = 0
Sda = 5 -- GPIO14
Scl = 6 -- GPIO12
Sla = 0x3c
i2c.setup(Id, Sda, Scl, i2c.SLOW)
Disp = u8g2.ssd1306_i2c_128x64_noname(Id, Sla)
print("Oled Init Success!");
Screen_WIFINAME = "";
Screen_IPADDRESS = "";
Screen_VERSION = "";
Screen_LightArr = {}
--tips user use pc tools to link-AP
function PageSerialNet()
1 year ago
Disp:clearBuffer()
Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(0,10,"Serial-LinkMode");
1 year ago
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(0,26,"Open NetTools.exe ");
Disp:drawStr(0,36,"input ssid and pwd.");
1 year ago
Disp:updateDisplay();
end
--progress:1-100,tips loading and update from server
function PageLoading(progress)
Disp:clearBuffer();
Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(40,10,"DYTech");
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(16,32,"Check for update");
Disp:drawFrame(12,42,104,10);
Disp:drawBox(14,44,progress,6);
Disp:updateDisplay();
end
function DrawMainScene(wifiName,ipAddress,version)
--Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(40,10,"DYTech");
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(0,26,"Wifi:"..wifiName);
Disp:drawStr(0,36,"Light Ctrl-UDP"..version);
Disp:drawStr(0,46,"S:"..ipAddress..":5000");
end
function DrawLight(lightArr)
1 year ago
Disp:drawCircle(16,56,4,u8g2.U8G2_DRAW_ALL);
Disp:drawCircle(32,56,4,u8g2.U8G2_DRAW_ALL);
Disp:drawCircle(48,56,4,u8g2.U8G2_DRAW_ALL);
Disp:drawCircle(64,56,4,u8g2.U8G2_DRAW_ALL);
Screen_LightArr = lightArr;
1 year ago
for index, value in ipairs(lightArr) do
if value then
Disp:drawDisc(16*index,56,4,u8g2.U8G2_DRAW_ALL);
end
end
if Is_AutoClose ~= nil then
if Is_AutoClose then
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(84,64,"Auto");
else
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(84,64,"Manual");
end
end
end
function PageMainScene(wifiName,ipAddress,version)
Screen_WIFINAME = wifiName;
Screen_IPADDRESS = ipAddress;
Screen_VERSION = version;
Disp:clearBuffer();
DrawMainScene(Screen_WIFINAME,Screen_IPADDRESS,Screen_VERSION)
Disp:updateDisplay();
--Disp:sendBuffer();
end
function PageLight(lightArr)
Disp:clearBuffer();
DrawMainScene(Screen_WIFINAME,Screen_IPADDRESS,Screen_VERSION);
DrawLight(lightArr);
1 year ago
Disp:sendBuffer();
end
function RefeshIP(ipAddress)
Screen_IPADDRESS = ipAddress;
Disp:clearBuffer();
DrawMainScene(Screen_WIFINAME,Screen_IPADDRESS,Screen_VERSION);
DrawLight(Screen_LightArr);
Disp:sendBuffer();
end
function PageConnecting()
Disp:clearBuffer()
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(0,10,"Connecting to internet");
Disp:drawStr(0,36,"Waiting...");
Disp:updateDisplay();
end
function PageConnectFaild(reason)
Disp:clearBuffer()
Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(0,10,"Connect Failed");
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(0,26,reason);
Disp:updateDisplay();
end