当前位置:网站首页>Raspberrypico analytic PWM
Raspberrypico analytic PWM
2022-07-25 08:02:00 【K.L.Zous】

Remote control receiver interface definition ( Sticker up ):
- The signal
- Positive pole
- Negative pole
Code ( Direct operation )
from machine import Pin, PWM
import utime
rc = Pin(0, Pin.IN)
# On board LED The lamp
led = PWM(Pin(25))
led.freq(200)
MAX=-1
MIN=99999
while True:
# Wait for the low level to end , Then record the time
while rc.value() == 0: # Capture the rising edge of the signal output
pass
time1 = utime.ticks_us()
# Wait for the high level to end , Then record the time
while rc.value() == 1: # Capture the falling edge of signal end output
pass
time2 = utime.ticks_us()
# Wait for the low level to end , Then record the time
while rc.value() == 0: # Capture the rising edge of the signal output
pass
time3 = utime.ticks_us()
period = time3 - time1
high_time = time2 - time1
low_time = time3 - time2
dc = (int)(high_time * 100 / period*100)
# print("---------------------------")
# print("dc=",dc)
utime.sleep(0.005)
if dc>MAX:
MAX=dc
elif dc<MIN:
MIN=dc
offset=MAX-MIN
# print("MAX=",MAX)
# print("MIN=",MIN)
# print("offset=",offset)
if offset!=0:
light=(int)((dc-MIN)/offset*65535)
# Control the onboard according to the stroke of the remote controller LED The brightness of the lamp
led.duty_u16(light)
print("light=",light)
Code ( interrupt )
Only the basic principles are written here , The specific implementation will not be repeated
# from machine Introduction in Pin, In order to control the pin later
from machine import Pin
# Configure keys
# key = machine.Pin(id, mode, pull)
# id:PICO Pin number . Here the key is set to and GPIO0 Connected to a
# mode: I / O mode , Yes Pin.IN( Input ) and Pin.OUT( Output ) Two kinds of . Set the input mode here
# pull: Up and down resistance configuration , Yes None( No pull-down resistance )、Pin.PULL_UP( Pull up resistance ) and Pin.PULL_DOWN( Pull down resistance ) Three
bt = Pin(24, Pin.IN, Pin.PULL_UP)
# On board LED The lamp
LED=Pin(25,Pin.OUT)
# Handling interrupts
def onClick(pin):
print(pin.value())
LED.toggle()
# interrupt
bt.irq(handler = onClick)
边栏推荐
- Acnet: asymmetric convolution for image hypersegmentation (with implementation code)
- [ES6] function parameters, symbol data types, iterators and generators
- [paper notes] effective CNN architecture design guided by visualization
- Learn when playing No 1 | can live classroom still be like this? Come and unlock "new posture"!
- Install MySQL 8.0 using docker
- Science: listening to music can really relieve pain. Chinese scientists reveal the neural mechanism behind it
- [unity introduction plan] interface Introduction (2) -games view & hierarchy & Project & Inspector
- CAS操作
- 刷题《剑指Offer》day02
- 交叉熵计算公式
猜你喜欢

Introduction and installation of mongodb

475-82(230、43、78、79、213、198、1143)

Teach you to understand the computer optometry sheet

Advanced C language (XII) - dynamic memory management

Enq: HW - fault analysis caused by content waiting

Didi - dispatching

App power consumption test
![[wechat applet] global style, local style, global configuration](/img/8e/c6241ab0f28e3f468dbfa923b91d20.png)
[wechat applet] global style, local style, global configuration

Redis core principles

牛客动态规划训练
随机推荐
MathWorks has been in China for 15 years. What are the secrets of continuous innovation?
7.24模拟赛总结
File details
P1048 [noip2005 popularization group t3] drug collection
Enq: HW - fault analysis caused by content waiting
机器学习入门详解(一):理解监督学习中的最大似然估计
[ES6] function parameters, symbol data types, iterators and generators
[unity introduction program] basic concept - preform prefab
Implement hot post | community project with timed tasks and cache
Network packet loss, network delay? This artifact helps you solve all problems
ACNet:用于图像超分的非对称卷积(附实现code)
Redis core principles
Efcore's solution of multi tenant zero script, table and database read-write separation under SaaS system
While (~scanf ("%d", & n)) is equivalent to while (scanf ("%d", & n)! =eof)
整数a按位取反(~)后的值为-(a+1)
Native form submission data
轮询、中断、DMA和通道
[paper notes] effective CNN architecture design guided by visualization
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 →