当前位置:网站首页>Epp+dis learning road (2) -- blink! twinkle!
Epp+dis learning road (2) -- blink! twinkle!
2022-07-07 12:11:00 【MakeMaker】
The last article finished the programming software and basic program upload , Copied a program to realize onboard LED The control of , Then learn this at the beginning of this article python The language , Let's first look at the program of the previous article :
import machine
pin = machine.Pin(2, machine.Pin.OUT)
pin.on()
The first 1 sentence import machine Is load machine modular , Only after loading, can we make ESP32 The pin of .
The first 2 sentence machine.Pin(2, machine.Pin.OUT) Will be 2 No. pin is defined as output pin
The first 3 sentence pin.on() Let this pin output high level , That is to say 3.3V
The control of this pin can also be written as follows :
pin.value(1)
They are the same .
Let's start with this LED The light flashes , First modify the procedure as follows :
import machine,time
pin = machine.Pin(2, machine.Pin.OUT)
pin.on()
time.sleep(1)
pin.off()
time.sleep(1)
It uses time.sleep(1), The meaning of this sentence is also obvious , Is to make ESP32 sleep 1 second , It's actually a delay 1 second , There are several ways to write :
time.sleep(1) # sleep 1 second
time.sleep_ms(500) # sleep 500 millisecond
time.sleep_us(10) # sleep 10 subtle
Of course use time Function must be loaded before time modular , You can follow me directly machine Back , Add a comma
Click the Green Run button , If you follow the previous article, it should be uploaded quickly , It's really just the ESP32 Inside main.py Covered it , If you just opened the software , The following dialog box will appear
Same choice MicroPython equipment
Then found ESP32 There are already main.py 了 , It's the program of our last class , Now just cover it !
Click Yes and it will be uploaded . Then you will find LED It's on 1 second , Then it went out , No flicker . Let's take a look at the program :
pin.on()
time.sleep(1)
pin.off()
time.sleep(1)
open LED, stop 1 second , Then turn it off and then stop 1 second , then ...... No, then . You can see micropython and Arduino The operating mechanism of is somewhat different ,Arduino Will continue to cycle loop() The sentence in , and micropython Only run the main program once . In order to keep it circulating , We have to write a similar loop() The sentence of :
import machine,time
pin = machine.Pin(2, machine.Pin.OUT)
while True:
pin.on()
time.sleep(1)
pin.off()
time.sleep(1)
We added number 3 sentence while True:
This is a while Loop statement , as long as while The following statement is true , The statements in the function will run circularly , We wrote directly while True: Then it will always be true , The statements in the function will run forever . Note that the statement contained in the function should be blank with the preceding four spaces , This is a python Programming format , stay C Inside is { }, stay python Inside, there are four blank spaces . Go to Baidu by yourself python Basic tutorials for .
Upload again , this time ESP32 Upper LED It will flash !
边栏推荐
- VIM command mode and input mode switching
- 《看完就懂系列》天哪!搞懂节流与防抖竟简单如斯~
- 108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]
- 2022 年第八届“认证杯”中国高校风险管理与控制能力挑战赛
- 5V串口接3.3V单片机串口怎么搞?
- SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
- 源代码防泄密中的技术区别再哪里
- Hi3516 full system type burning tutorial
- TypeScript 接口继承
- Zero shot, one shot and few shot
猜你喜欢
<No. 8> 1816. Truncate sentences (simple)
[filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]
Zero shot, one shot and few shot
超标量处理器设计 姚永斌 第10章 指令提交 摘录
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
消息队列消息丢失和消息重复发送的处理策略
Mastering the new functions of swiftui 4 weatherkit and swift charts
Visual studio 2019 (localdb) \mssqllocaldb SQL Server 2014 database version is 852 and cannot be opened. This server supports version 782 and earlier
STM32F1与STM32CubeIDE编程实例-315M超再生无线遥控模块驱动
Hi3516全系统类型烧录教程
随机推荐
数据库系统原理与应用教程(008)—— 数据库相关概念练习题
Sonar:Cognitive Complexity认知复杂度
Ask about the version of flinkcdc2.2.0, which supports concurrency. Does this concurrency mean Multiple Parallelism? Now I find that mysqlcdc is full
消息队列消息丢失和消息重复发送的处理策略
【最短路】Acwing1128信使:floyd最短路
Completion report of communication software development and Application
In SQL, I want to set foreign keys. Why is this problem
Upgrade from a tool to a solution, and the new site with praise points to new value
TypeScript 接口继承
Nuclear boat (I): when "male mothers" come into reality, can the biotechnology revolution liberate women?
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
什么是局域网域名?如何解析?
110.网络安全渗透测试—[权限提升篇8]—[Windows SqlServer xp_cmdshell存储过程提权]
VIM command mode and input mode switching
《看完就懂系列》天哪!搞懂节流与防抖竟简单如斯~
Camera calibration (1): basic principles of monocular camera calibration and Zhang Zhengyou calibration
Review and arrangement of HCIA
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
超标量处理器设计 姚永斌 第10章 指令提交 摘录
千人规模互联网公司研发效能成功之路