ESP8266 的几个代码 加深对LUA的理解
--some functions
dofile("functions.lua")
lighton1=
lighton2=
lighton3=
lighton4= pin1 =
pin2 =
pin3 =
pin4 =
gpio.mode(pin1,gpio.OUTPUT)
gpio.mode(pin2,gpio.OUTPUT)
gpio.mode(pin3,gpio.OUTPUT)
gpio.mode(pin4,gpio.OUTPUT) --pin1
tmr.alarm(,,,function()
if lighton1== then
lighton1=
gpio.write(pin1,gpio.LOW)
-- 512/1024, 50% duty cycle
else
lighton1=
gpio.write(pin1,gpio.HIGH)
end
end)
--pin2
tmr.alarm(,,,function()
if lighton2== then
lighton2=
gpio.write(pin2,gpio.LOW)
-- 512/1024, 50% duty cycle
else
lighton2=
gpio.write(pin2,gpio.HIGH)
end
end)
--pin3
tmr.alarm(,,,function()
if lighton3== then
lighton3=
gpio.write(pin3,gpio.LOW)
-- 512/1024, 50% duty cycle
else
lighton3=
gpio.write(pin3,gpio.HIGH)
end
end)
--pin4
tmr.alarm(,,,function()
if lighton4== then
lighton4=
gpio.write(pin4,gpio.LOW)
-- 512/1024, 50% duty cycle
else
lighton4=
gpio.write(pin4,gpio.HIGH)
end
end)
dofile("sjson.lua")
--inti.lua
--sjson.lua
name = "lxx"
print("Hello world!")
print(name .. ",nihao!")
--functions.lua
function startup()
if file.open("init.lua") == nil then
print("init.lua deleted or renamed")
else
print("Running")
file.close("init.lua")
-- the actual application is stored in 'application.lua'
-- dofile("application.lua")
end
end -- Define WiFi station event callbacks
wifi_connect_event = function(T)
print("Connection to AP("..T.SSID..") established!")
print("Waiting for IP address...")
if disconnect_ct ~= nil then disconnect_ct = nil end
end wifi_got_ip_event = function(T)
-- Note: Having an IP address does not mean there is internet access!
-- Internet connectivity can be determined with net.dns.resolve().
print("Wifi connection is ready! IP address is: "..T.IP)
print("Startup will resume momentarily, you have 3 seconds to abort.")
print("Waiting...")
tmr.create():alarm(, tmr.ALARM_SINGLE, startup)
end wifi_disconnect_event = function(T)
if T.reason == wifi.eventmon.reason.ASSOC_LEAVE then
--the station has disassociated from a previously connected AP
return
end
-- total_tries: how many times the station will attempt to connect to the AP. Should consider AP reboot duration.
local total_tries =
print("\nWiFi connection to AP("..T.SSID..") has failed!") --There are many possible disconnect reasons, the following iterates through
--the list and returns the string corresponding to the disconnect reason.
for key,val in pairs(wifi.eventmon.reason) do
if val == T.reason then
print("Disconnect reason: "..val.."("..key..")")
break
end
end if disconnect_ct == nil then
disconnect_ct =
else
disconnect_ct = disconnect_ct +
end
if disconnect_ct < total_tries then
print("Retrying connection...(attempt "..(disconnect_ct+).." of "..total_tries..")")
else
wifi.sta.disconnect()
print("Aborting connection to AP!")
disconnect_ct = nil
end
end
ESP8266 的几个代码 加深对LUA的理解的更多相关文章
- 8天入门docker系列 —— 第二天 通过一个aspnetcore程序加深对容器的理解
我们知道容器是一个打包了应用和相关依赖的盒子,那怎么去操控这个盒子呢? 这一篇我通过一个简单的aspnetcore程序来加深对盒子的理解,使用之前先 安装一下Docker的环境. 一:Docker的安 ...
- ESP8266开发综合篇第十四节(LUA)-8266作为TCP服务器,Android客户端连接,显示温湿度,控制继电器
前几节先略过,我先补充上大部分人迫切的需求 编写Android TCP客户端 用Android Studio 先做一下界面 然后放一个输入对话框,因为没有显示出来这个控件.所以就手写 剩下的自己研究 ...
- cocos2dx 3.x c++代码打包给lua调用过程(mac)
下载cocos2dx 框架,在应用程序->cocos->framework->cocos2d-x-3.x->tools->tolua目录下,一个ini文件对应一个py文件 ...
- Java中静态代码块,代码块,构造方法的理解
直接贴代码 class A { static { System.out.println("父类静态代码区"); } { System.out.println("父类代码区 ...
- java面向对象(封装-继承-多态)
框架图 理解面向对象 面向对象是相对面向过程而言 面向对象和面向过程都是一种思想 面向过程强调的是功能行为 面向对象将功能封装进对象,强调具备了功能的对象. 面向对象是基于面向过程的. 面向对象的特点 ...
- 适合初学者的嵌入式Linux计划
俗话说万事开头难,刚开始的时候,你是否根本就不知如何开始,上网查资料被一堆堆新名词搞的找不到北,去图书馆看书也是找不到方向?又是arm,又是linux,又是uboot头都大了,不知道自己究竟从哪里开始 ...
- Python基础入门(6)- 面向对象编程
1.初识面向对象 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的.本篇随笔将详细介绍Python的面向对象编程. 如果你以前没有接触过面向对象 ...
- 5道面试题,拿捏String底层原理!
原创:微信公众号 码农参上,欢迎分享,转载请保留出处. String字符串是我们日常工作中常用的一个类,在面试中也是高频考点,这里Hydra精心总结了一波常见但也有点烧脑的String面试题,一共5道 ...
- Lua 学习笔记(七)编译、执行外部代码块
Lua称为解释型语言的原因:Lua允许在运行源代码之前,先将源代码预编译为一种中间形式.区别解释型语言的主要特征是在于编译器是否是语言运行时库的一部分,即有能力执行动态生成的代码.因为Lua中有dof ...
随机推荐
- SqlServer 对分组的内容进行拼接-group_concat
SqlServer 对分组的内容进行拼接: 方案1:xml 子集,性能较差 方案2:借助 sqlCLR 接入.实现group_concat.性能完美,但是 阿里云的不支持!!!! CREATE TA ...
- MySQL MySql连接数与线程池
连接数 1. 查看允许的最大并发连接数 SHOW VARIABLES LIKE 'max_connections'; 2. 修改最大连接数 方法1:临时生效 SET GLOBAL max_conn ...
- Sql Server查询性能优化之不可小觑的书签查找
小小程序猿SQL Server认知的成长 1.没毕业或工作没多久,只知道有数据库.SQL这么个东东,浑然分不清SQL和Sql Server Oracle.MySql的关系,通常认为SQL就是SQL S ...
- What-does-git-remote-and-origin-mean
https://www.quora.com/What-does-git-remote-and-origin-mean https://stackoverflow.com/questions/29235 ...
- 图灵数学·统计学丛书.PDF(53本全)
图灵数学·统计学丛书01-概率论及其应用(第1卷·第3版)-[美]William.Feller-人民邮电出版社.pdf 图灵数学·统计学丛书01-金融数学:衍生产品定价引论-[英]M·巴克斯特& ...
- 【Spark 深入学习 07】RDD编程之旅基础篇03-键值对RDD
--------------------- 本节内容: · 键值对RDD出现背景 · 键值对RDD转化操作实例 · 键值对RDD行动操作实例 · 键值对RDD数据分区 · 参考资料 --------- ...
- openfire开发文档
http://www.blogjava.net/yi88han/archive/2009/02/11/254203.html
- java框架篇---hibernate(多对多)映射关系
以学生和老师为例的来讲解多对多映射. 实体类: Student package cn.itcast.g_hbm_manyToMany; import java.util.HashSet; import ...
- 【转帖】流程与IT管理部——IT支撑业务变革的必然趋势
流程与IT管理部——IT支撑业务变革的必然趋势 1前言 伴随着中国企业的信息化进程, IT部门.IT专职人员已经在大部分企业获得了一席之地,电脑.网络.软件的维护都离不开这个部门:不过“一席之地”并不 ...
- laravel中artisan的用法
如: