当前位置:网站首页>Raspberry pie 4B parsing PWM
Raspberry pie 4B parsing PWM
2022-07-25 08:02:00 【K.L.Zous】

#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
pin=18
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN)
while True:
# Wait for the low level to end , Then record the time
while GPIO.input(pin) == 0: # Capture the rising edge of the signal output
pass
time1 = time.time()
# Wait for the high level to end , Then record the time
while GPIO.input(pin) == 1: # Capture the falling edge of signal end output
pass
time2 = time.time()
# Wait for the low level to end , Then record the time
while GPIO.input(pin) == 0: # Capture the rising edge of the signal output
pass
time3 = time.time()
#print(time1)
#print(time2)
#print(time3)
period = time3 - time1
high_time = time2 - time1
low_time = time3 - time2
duty_cycle = (int)(high_time * 100 / period*100)
print(duty_cycle)
time.sleep(0.1)
#print("-------------------------")
边栏推荐
- P1047 [NOIP2005 普及组 T2] 校门外的树
- Learn when playing No 5 | human high quality examination, right here →
- How to reverse a stack with recursive functions and stack operations only
- Hikaricp connection pool does not operate for a period of time, and the data is automatically disconnected
- 整数a按位取反(~)后的值为-(a+1)
- 查看电脑重启次数、原因
- Science: listening to music can really relieve pain. Chinese scientists reveal the neural mechanism behind it
- 转行学什么成为了一大部分人的难题,那么为什么很多人学习软件测试呢?
- Interview questions: common faults and occurrence scenarios of redis
- toolbar的使用
猜你喜欢

The 17th revitalization cup computer programmer (cloud computing platform operation and development) finals
![[software testing] package resume from these points to improve the pass rate](/img/69/b27255c303150430df467ff3b5cd08.gif)
[software testing] package resume from these points to improve the pass rate

Network packet loss, network delay? This artifact helps you solve all problems

【软件测试】包装简历从这几点出发、提升通过率

ArcGIS Pro脚本工具(10)——从图层生成.stylx样式符号

Recommend 7 open source projects of yyds this week
![[unity introduction program] basic concepts - 2D collider collider 2D](/img/cf/a546238a5eaf4707006ecf1b7f19c6.png)
[unity introduction program] basic concepts - 2D collider collider 2D

File details

Hikaricp connection pool does not operate for a period of time, and the data is automatically disconnected

Native form submission data
随机推荐
Pricing is arbitrary, products are difficult to distinguish between true and false, and platforms are running away. Will the Tibetan market continue to be popular?
Learn when playing No 5 | human high quality examination, right here →
机器学习理论及案例分析(part1)--机器学习基础
[unity entry plan] interface Introduction (1) -scene view
Advanced C language (XII) - dynamic memory management
Mysql-5.7 installation
How does MTK change the boot logo?
P1048 [noip2005 popularization group t3] drug collection
One of C language multithreading programming
Big guy Qiu zhaomianjing
Problems easily ignored by POM
Practical operation: elegant downtime under large-scale micro service architecture
【软件测试】包装简历从这几点出发、提升通过率
Vscode remote connection server, switch to go version
Competition path design of beacon group
Cerebral cortex: the relationship between lifestyle and brain function in the elderly and its relationship with cognitive decline
Enq: HW - fault analysis caused by content waiting
A queue of two stacks
用一个栈实现另一个栈的排序
[audio and video] picture YUV data format