当前位置:网站首页>Raspberrypico analytic PWM
Raspberrypico analytic PWM
2022-07-28 20:19: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)
边栏推荐
- [in depth study of 4g/5g/6g topics -44]: urllc-15 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -9-low delay technology -3-non slot scheduling mini
- Data system of saltstack
- C语言数据 3(2)
- Store and guarantee rancher data based on Minio objects
- WFST decoding process
- XOR operation and its usage
- 9. Pointer of C language (5) how many bytes does the pointer variable occupy
- 跨区域网络的通信学习静态路由
- Solve the kangaroo crossing problem (DP)
- Solve flask integration_ Error reporting in restplus
猜你喜欢

Const pointer of C language and parameter passing of main function

zfoo增加类似于mydog的路由

Solve the cookie splitting problem (DP)

The privatized instant messaging platform protects the security of enterprise mobile business
![[C language] simulation implementation of pow function (recursion)](/img/7b/ef8b3d97adc7810de249a37642c71f.png)
[C language] simulation implementation of pow function (recursion)
![[C language] Pointer advanced knowledge points](/img/8f/0057243c603ddfe20381c9bd446f03.png)
[C language] Pointer advanced knowledge points
![[C language] 5000 word super detailed explanation of various operations of the sequence table](/img/3b/932526e96ef14df8a321048e9c14b4.png)
[C language] 5000 word super detailed explanation of various operations of the sequence table

Tencent cloud deployment lamp_ Experience of building a station
![[C language] initial C language reflection and summary](/img/21/826d144867f7a73ec2cd8896a5250a.png)
[C language] initial C language reflection and summary

Reverse string
随机推荐
NEIL: Extracting Visual Knowledge from Web Data
[C language] function
C language pointer and two-dimensional array
熊市下PLATO如何通过Elephant Swap,获得溢价收益?
长轮询,iframe和sse三种web消息实时推送demo实践
Using Lex (Flex) to generate lexical analyzer of PL language
Longest Palindromic Substring
Source code analysis of scripy spider
JS preventdefault() keyboard input limit onmousewheel stoppropagation stop event propagation
[C language] Pointer elementary knowledge points
8. Compilation errors of C language and Chinese explanation
A chip company fell in round B
C语言数据 3(2)
Basic mathematical knowledge (update)
Implementation of strcat in C language
What is the variance?
How to automatically store email attachments in SharePoint
Use of strtok and strError
Cdga | how can the industrial Internet industry do a good job in data governance?
Tencent cloud deployment lamp_ Experience of building a station