当前位置:网站首页>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)
边栏推荐
- Token verification program index.php when configuring wechat official account server
- C language - control statement
- Stories of Party members | Li qingai uses cartoons to drive farmers to increase income and become rich
- [C language] summary of methods for solving the greatest common divisor
- Item exception handling in SSM
- [C language] Gobang game [array and function]
- Labelme (I)
- XOR operation and its usage
- Sequential linear table - practice in class
- Multi-Modal Knowledge Graph Construction and Application: A Survey
猜你喜欢
![[C language] advanced pointer exercise 1](/img/ee/c62919330edb4a0b5a2a4b027e5b5c.png)
[C language] advanced pointer exercise 1

3、 Are formal and actual parameters in a programming language variables?

Rand function generates pseudo-random numbers
![[C language] Pointer advanced knowledge points](/img/8f/0057243c603ddfe20381c9bd446f03.png)
[C language] Pointer advanced knowledge points

83.(cesium之家)cesium示例如何运行

熊市下PLATO如何通过Elephant Swap,获得溢价收益?

English translation Arabic - batch English translation Arabic tools free of charge

2022年下半年系统集成项目管理工程师认证8月20日开班

ssm中项目异常处理

Multi-Modal Knowledge Graph Construction and Application: A Survey
随机推荐
C+ + core programming
2、 Relationship between software operation and memory
Solve the cookie splitting problem (DP)
Use of strtok and strError
Solve the problem of adding the least number of parentheses (interval DP)
9. Pointer of C language (4) pointer and one-dimensional array, pointer operation
robobrowser的简单使用
What is the process of swing event processing?
Array out of bounds
七种轮询介绍(后附实践链接)
local/chain/run_ tdnn.sh:
熊市下PLATO如何通过Elephant Swap,获得溢价收益?
Hebei: stabilizing grain and expanding beans to help grain and oil production improve quality and efficiency
DSACTF7月re
[C language] string reverse order implementation (recursion and iteration)
Common modules of saltstack
Source code analysis of scripy spider
HSETNX KEY_NAME FIELD VALUE 用法
C language - pointer
C language pointer and two-dimensional array