2017年3月9日 星期四

Micropython ESP8266 中断

外部中斷modePin.IN  輸入
      Pin.OUT 輸出
      value:輸出電平
      Pin.value[value])不帶參數時是讀取輸入電平,帶參數時是設置輸出電平,參數是1/0.
      Pin.irq(*,trigger, handler=None)
     
中斷
      trigger,觸發方式
      Pin.IRQ_FALLING,下降沿
      Pin.IRQ_RISING,上升沿
      Pin.IN,上升下降沿
      handler,回呼函數

中斷函數程式:
1.  from machine import Pin
2.  value=1
3.  counter=0
4.  def func(v):
5.      global value,counter
6.      counter+=1
7.      led.value(value)
8.      if(value == 0):
9.         value = 1
10.    else:
11.      value = 0
12.print("IRQ ",counter)
13.led = Pin(14, Pin.OUT)
14.led.value(0)
15.button = Pin(0, Pin.IN)
16.button.irq(trigger=Pin.IRQ_FALLING, handler=func)
17.while True:
18.      pass
19. 






沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...