Easy-Python  1.00.00Change to: 中文
Key

Functions

 KEY (id)
 Make new KEY object. More...
 
 value ()
 Get KEY current value. More...
 
 irq (trigger, handler)
 Set KEY irq function. More...
 

Detailed Description

The KEY object controls an individual KEY and it inherits the PIN object

KEY Example of Micropython
Click here
Example Code of usage:
from machine import KEY
from machine import PIN
irq_count = 0
p=PIN('P12') ##P4.4
p.mode(PIN.OUT)
p.value(0)
def toggle(t):
if p.value() == 0:
p.value(1)
else :
p.value(0)
k=KEY(1)
k.value()
k.irq(trigger=PIN.IRQ_BOTH,handler=toggle)

Function Documentation

KEY ( id  )

Make new KEY object.

Create an KEY object associated with the given KEY:

Parameters
[in]idis the KEY number 0~3
Returns
(no)
Example of usage:
from machine import KEY
key=KEY(0)
value ( )

Get KEY current value.

KEY.value()

Parameters
no
Returns
(no)
Example of usage:
from machine import KEY
k=KEY(1)
k.value()
irq ( trigger  ,
handler   
)

Set KEY irq function.

Parameters
[in]triggercan be one of:
  • PIN.IRQ_BOTH : Set irq falling and risging edge trigger mode.
  • PIN.IRQ_FALLING : Set irq falling edge trigger mode.
  • PIN.IRQ_RISING : Set irq risging edge trigger mode.
  • PIN.IRQ_LOW_LEVEL : Set irq low level trigger mode.
  • PIN.IRQ_HIGH_LEVEL : Set irq high level trigger mode.
[in]handleris an optional function to be called when the interrupt is triggered.
Returns
(no)
Example of usage:
from machine import KEY
from machine import PIN
p=PIN('P12') ##P4.4
p.mode(PIN.OUT)
p.value(0)
def toggle(t):
if p.value() == 0:
p.value(1)
else :
p.value(0)
k=KEY(1)
k.value()
k.irq(trigger=PIN.IRQ_BOTH,handler=toggle)