当前位置:网站首页>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 !
边栏推荐
- 消息队列消息丢失和消息重复发送的处理策略
- NPC Jincang was invited to participate in the "aerospace 706" I have an appointment with aerospace computer "national Partner Conference
- UP Meta—Web3.0世界创新型元宇宙金融协议
- 超标量处理器设计 姚永斌 第8章 指令发射 摘录
- 免备案服务器会影响网站排名和权重吗?
- SwiftUI Swift 内功之 Swift 中使用不透明类型的 5 个技巧
- Rationaldmis2022 advanced programming macro program
- Sonar:cognitive complexity
- [shortest circuit] acwing1128 Messenger: Floyd shortest circuit
- Simple network configuration for equipment management
猜你喜欢
powershell cs-UTF-16LE编码上线
Unity map auto match material tool map auto add to shader tool shader match map tool map made by substance painter auto match shader tool
ENSP MPLS layer 3 dedicated line
【纹理特征提取】基于matlab局部二值模式LBP图像纹理特征提取【含Matlab源码 1931期】
【滤波跟踪】基于matlab捷联惯导仿真【含Matlab源码 1935期】
Detailed explanation of debezium architecture of debezium synchronization
Rationaldmis2022 advanced programming macro program
从工具升级为解决方案,有赞的新站位指向新价值
Swiftui tutorial how to realize automatic scrolling function in 2 seconds
软件内部的定时炸弹:0-Day Log4Shell只是冰山一角
随机推荐
问题:先后键入字符串和字符,结果发生冲突
Sonar:Cognitive Complexity认知复杂度
如何理解服装产业链及供应链
111.网络安全渗透测试—[权限提升篇9]—[Windows 2008 R2内核溢出提权]
Superscalar processor design yaoyongbin Chapter 8 instruction emission excerpt
2022 8th "certification Cup" China University risk management and control ability challenge
Camera calibration (1): basic principles of monocular camera calibration and Zhang Zhengyou calibration
ENSP MPLS layer 3 dedicated line
About how to install mysql8.0 on the cloud server (Tencent cloud here) and enable local remote connection
Fleet tutorial 14 basic introduction to listtile (tutorial includes source code)
总结了200道经典的机器学习面试题(附参考答案)
College entrance examination composition, high-frequency mention of science and Technology
idea 2021中文乱码
让数字管理好库存
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
Tsinghua Yaoban programmers, online marriage was scolded?
Flet tutorial 17 basic introduction to card components (tutorial includes source code)
Flet教程之 15 GridView 基础入门(教程含源码)
免备案服务器会影响网站排名和权重吗?
防红域名生成的3种方法介绍