当前位置:网站首页>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 !
边栏推荐
- Completion report of communication software development and Application
- Have you ever met flick Oracle CDC, read a table without update operation, and read it repeatedly every ten seconds
- 【神经网络】卷积神经网络CNN【含Matlab源码 1932期】
- 《通信软件开发与应用》课程结业报告
- Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
- Completion report of communication software development and Application
- Fleet tutorial 15 introduction to GridView Basics (tutorial includes source code)
- 112. Network security penetration test - [privilege promotion article 10] - [Windows 2003 lpk.ddl hijacking rights lifting & MSF local rights lifting]
- 关于 Web Content-Security-Policy Directive 通过 meta 元素指定的一些测试用例
- 牛客网刷题网址
猜你喜欢

ES底层原理之倒排索引

Camera calibration (1): basic principles of monocular camera calibration and Zhang Zhengyou calibration

UP Meta—Web3.0世界创新型元宇宙金融协议

EPP+DIS学习之路(2)——Blink!闪烁!

Up meta - Web3.0 world innovative meta universe financial agreement

Hi3516全系统类型烧录教程
![[filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]](/img/ae/52cdc98fb9db8c0d0776b8274ecd39.png)
[filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]

《通信软件开发与应用》课程结业报告

Hi3516 full system type burning tutorial

【紋理特征提取】基於matlab局部二值模式LBP圖像紋理特征提取【含Matlab源碼 1931期】
随机推荐
Various uses of vim are very practical. I learned and summarized them in my work
Xiaohongshu microservice framework and governance and other cloud native business architecture evolution cases
【最短路】Acwing1128信使:floyd最短路
Superscalar processor design yaoyongbin Chapter 10 instruction submission excerpt
The function of adding @ before the path in C #
Flet教程之 17 Card卡片组件 基础入门(教程含源码)
数据库系统原理与应用教程(009)—— 概念模型与数据模型
开发一个小程序商城需要多少钱?
Basic introduction to the 16 tabs tab control in the fleet tutorial (the tutorial includes source code)
Fleet tutorial 19 introduction to verticaldivider separator component Foundation (tutorial includes source code)
<No. 9> 1805. 字符串中不同整数的数目 (简单)
【数据聚类】基于多元宇宙优化DBSCAN实现数据聚类分析附matlab代码
Solve the problem that vscode can only open two tabs
Hi3516 full system type burning tutorial
顶级域名有哪些?是如何分类的?
【玩转 RT-Thread】 RT-Thread Studio —— 按键控制电机正反转、蜂鸣器
SwiftUI 教程之如何在 2 秒内实现自动滚动功能
Flet教程之 14 ListTile 基础入门(教程含源码)
30. Few-shot Named Entity Recognition with Self-describing Networks 阅读笔记
Completion report of communication software development and Application