当前位置:网站首页>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)
边栏推荐
- Merge sort template
- [C language] Fibonacci sequence [recursion and iteration]
- Reverse string
- [C language] summary of methods for solving the greatest common divisor
- 9. Pointer of C language (4) pointer and one-dimensional array, pointer operation
- 9. Pointer of C language (5) how many bytes does the pointer variable occupy
- 河北邯郸:拓展基层就业空间 助力高校毕业生就业
- Maximum exchange [greedy thought & monotonic stack implementation]
- 2. Floating point number, the difference between float and double in C language and how to choose them
- Implementation of strstr in C language
猜你喜欢

Reverse string
![[C language] Pointer advanced knowledge points](/img/8f/0057243c603ddfe20381c9bd446f03.png)
[C language] Pointer advanced knowledge points

“中国网事·感动2022”二季度网络感动人物评选结果揭晓

为什么客户支持对SaaS公司很重要?

Deploy ZABBIX automatically with saltstack

C language - data storage

【CodeForces】Educational Codeforces Round 132 (Rated for Div. 2)

What is the process of swing event processing?

产品经理访谈 | 第五代验证码的创新与背景

【实验分享】CCIE—BGP反射器实验
随机推荐
Simple use of robobrowser
zfoo增加类似于mydog的路由
1. C language variable type, global variable, local variable
2、 Relationship between software operation and memory
English translation Italian - batch English translation Italian tools free of charge
JVM (24) -- performance monitoring and tuning (5) -- Analyzing GC logs
JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver
flask_ Mail source code error
Multi-Modal Knowledge Graph Construction and Application: A Survey
[C language] simulation implementation of strlen (recursive and non recursive)
[C language] summary of methods for solving the greatest common divisor
基于 MinIO 对象存储保障 Rancher 数据
[C language] string reverse order implementation (recursion and iteration)
In the second half of 2022, the system integration project management engineer certification starts on August 20
Implementation of memmove in C language
C language operators and input and output
2. Floating point number, the difference between float and double in C language and how to choose them
[C language] simulation implementation of pow function (recursion)
[C language] Gobang game [array and function]
C language functions and pointers