--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的理解的更多相关文章

  1. 8天入门docker系列 —— 第二天 通过一个aspnetcore程序加深对容器的理解

    我们知道容器是一个打包了应用和相关依赖的盒子,那怎么去操控这个盒子呢? 这一篇我通过一个简单的aspnetcore程序来加深对盒子的理解,使用之前先 安装一下Docker的环境. 一:Docker的安 ...

  2. ESP8266开发综合篇第十四节(LUA)-8266作为TCP服务器,Android客户端连接,显示温湿度,控制继电器

    前几节先略过,我先补充上大部分人迫切的需求 编写Android TCP客户端  用Android Studio 先做一下界面 然后放一个输入对话框,因为没有显示出来这个控件.所以就手写 剩下的自己研究 ...

  3. cocos2dx 3.x c++代码打包给lua调用过程(mac)

    下载cocos2dx 框架,在应用程序->cocos->framework->cocos2d-x-3.x->tools->tolua目录下,一个ini文件对应一个py文件 ...

  4. Java中静态代码块,代码块,构造方法的理解

    直接贴代码 class A { static { System.out.println("父类静态代码区"); } { System.out.println("父类代码区 ...

  5. java面向对象(封装-继承-多态)

    框架图 理解面向对象 面向对象是相对面向过程而言 面向对象和面向过程都是一种思想 面向过程强调的是功能行为 面向对象将功能封装进对象,强调具备了功能的对象. 面向对象是基于面向过程的. 面向对象的特点 ...

  6. 适合初学者的嵌入式Linux计划

    俗话说万事开头难,刚开始的时候,你是否根本就不知如何开始,上网查资料被一堆堆新名词搞的找不到北,去图书馆看书也是找不到方向?又是arm,又是linux,又是uboot头都大了,不知道自己究竟从哪里开始 ...

  7. Python基础入门(6)- 面向对象编程

    1.初识面向对象 Python从设计之初就已经是一门面向对象的语言,正因为如此,在Python中创建一个类和对象是很容易的.本篇随笔将详细介绍Python的面向对象编程. 如果你以前没有接触过面向对象 ...

  8. 5道面试题,拿捏String底层原理!

    原创:微信公众号 码农参上,欢迎分享,转载请保留出处. String字符串是我们日常工作中常用的一个类,在面试中也是高频考点,这里Hydra精心总结了一波常见但也有点烧脑的String面试题,一共5道 ...

  9. Lua 学习笔记(七)编译、执行外部代码块

    Lua称为解释型语言的原因:Lua允许在运行源代码之前,先将源代码预编译为一种中间形式.区别解释型语言的主要特征是在于编译器是否是语言运行时库的一部分,即有能力执行动态生成的代码.因为Lua中有dof ...

随机推荐

  1. IOS项目目录结构和开发流程

    网上相关的资源不多,开源的且质量还不错的iOS项目也是少之又少,最近正好跟同事合作了一个iOS项目,来说说自己的一些想法.   目录结构 AppDelegate Models Macro Genera ...

  2. 运行第一个Docker容器-Docker for Web Developers(1)

    1. Docker介绍 Docker由dotCloud公司发起的一个内部项目,后来Docker火了,dotCloud公司改名为Docker了: Docker使用了Go语言开发,基于 Linux 内核的 ...

  3. 【Big Data - Hadoop - MapReduce】初学Hadoop之图解MapReduce与WordCount示例分析

    Hadoop的框架最核心的设计就是:HDFS和MapReduce.HDFS为海量的数据提供了存储,MapReduce则为海量的数据提供了计算. HDFS是Google File System(GFS) ...

  4. 【30集iCore3_ADP出厂源代码(ARM部分)讲解视频】30-11层驱动之FSMC

    视频简介:该视频介绍iCore3应用开发平台中FSMC通信的配置方法及ARM与FPGA通信的方法. 源视频包下载地址:链接:http://pan.baidu.com/s/1slbHOCH 密码:n06 ...

  5. Halcon 之dyn_threshold与threshold区别与用法

    相同点:都是为了选择想要的灰度区域 dyn_threshold (OrigImage, MeanImage, SmallRaw, 3, 'light')  //动态阈值分割 threshold()// ...

  6. Go语言实践_实现一(服务器端)对多(客户端)在线聊天室

    一.目的 运用Go语言中的goroutine和通道实现一个简单的一个服务器端对多个客户端的在线聊天 软件环境:Goland,Go1.9 代码仓库链接 二.设计思路 与一对一的设计思路类似,就是加了个线 ...

  7. 零基础 Vue 开发环境搭建 打开运行Vue项目

    [相关推荐]IntellIJ IDEA 配置 Vue 支持 打开Vue项目 所需文件 node.js环境(npm包管理器)(node-v8.11.3-x64.msi)(npmV5.6.0) cnpm ...

  8. Ubuntu 14.04 安装 Blender,并放桌面

    1.打开Blender官网 2.在主页点击down按钮,跳转到下载页面 3.根据自己的操作系统,选择合适的版本,这里使用的是ubunut 64位,所以下载Linux 64bit,保存文件,一般保存到h ...

  9. SpringBoot整合Mail

    前言 SpringBoot实现邮件功能是非常的方便快捷的,因为SpringBoot默认有starter实现了Mail. 发送邮件应该是网站的必备功能之一,什么注册验证,忘记密码或者是给用户发送营销信息 ...

  10. 小程序返回顶部top滚动

    wxjs const app = getApp(); Page({ data:{ // top标签显示(默认不显示) backTopValue:false }, // 监听滚动条坐标 onPageSc ...