当前位置:网站首页>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 machinepin = 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,timepin = 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,timepin = 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 !
边栏推荐
- What is high cohesion and low coupling?
- wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
- 108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]
- 【神经网络】卷积神经网络CNN【含Matlab源码 1932期】
- 110. Network security penetration test - [privilege promotion 8] - [windows sqlserver xp_cmdshell stored procedure authorization]
- Introduction to three methods of anti red domain name generation
- [neural network] convolutional neural network CNN [including Matlab source code 1932]
- Swiftui swift internal skill: five skills of using opaque type in swift
- Mise en œuvre du codage Huffman et du décodage avec interface graphique par MATLAB
- Tsinghua Yaoban programmers, online marriage was scolded?
猜你喜欢

人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》

About how to install mysql8.0 on the cloud server (Tencent cloud here) and enable local remote connection

Summed up 200 Classic machine learning interview questions (with reference answers)

Swiftui tutorial how to realize automatic scrolling function in 2 seconds
![[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]](/img/65/bf1d0f82878a49041e8c2b3a84bc15.png)
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]

@What happens if bean and @component are used on the same class?

<No. 8> 1816. Truncate sentences (simple)

Tsinghua Yaoban programmers, online marriage was scolded?
![108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]](/img/c0/8a7b52c46eadd27cf4784ab2f32002.png)
108. Network security penetration test - [privilege escalation 6] - [windows kernel overflow privilege escalation]

<No. 9> 1805. Number of different integers in the string (simple)
随机推荐
《通信软件开发与应用》课程结业报告
110. Network security penetration test - [privilege promotion 8] - [windows sqlserver xp_cmdshell stored procedure authorization]
消息队列消息丢失和消息重复发送的处理策略
小红书微服务框架及治理等云原生业务架构演进案例
Swiftui tutorial how to realize automatic scrolling function in 2 seconds
[texture feature extraction] LBP image texture feature extraction based on MATLAB local binary mode [including Matlab source code 1931]
Visual Studio 2019 (LocalDB)\MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782版及更低版本
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
Upgrade from a tool to a solution, and the new site with praise points to new value
@What happens if bean and @component are used on the same class?
The function of adding @ before the path in C #
SwiftUI Swift 内功之如何在 Swift 中进行自动三角函数计算
Matlab implementation of Huffman coding and decoding with GUI interface
【全栈计划 —— 编程语言之C#】基础入门知识一文懂
防红域名生成的3种方法介绍
Apache installation problem: configure: error: APR not found Please read the documentation
Swiftui swift internal skill: five skills of using opaque type in swift
Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
从工具升级为解决方案,有赞的新站位指向新价值
[filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]