logo

请问外部中断的函数具体是如何实现的啊,要实现的就是通过外部中断改变全局变量的值,返回给主程序中,让其执行不同的内容?

2018-10-03 16:13
R
gcaf
import sensor, image, pyb,  micropython, utime


micropython.alloc_emergency_exception_buf(100)
from pyb import Pin

global bull
bull=1

def callback(line):
    global bull
    bull=bull+1
    extint.disable()

extint = pyb.ExtInt(Pin('P7'), pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_UP, callback)


while(bull==1):
    utime.sleep(1)
    print(bull)
    utime.sleep(1)

if bull==2:
    utime.sleep(1)
    print(bull)
    extint.enable()
    utime.sleep(1)
 

if bull==3:
    utime.sleep(1)
    print(bull)
    extint.enable()
    utime.sleep(1)

if(True):
    print('Hello,World')
    utime.sleep_ms(500) 
    print(bull)
2018-10-04 15:20
I
网红小智智 星瞳科技

你的if应该在死循环里面。