Code: Select all
from machine import Pin
p0 = Pin('X0', Pin.OUT)
print("p0 = 0")
p0.value(0)
print("p0 = 1")
p0.value(1)
p2 = Pin('Y0', Pin.IN, Pin.PULL_UP)
print("p2 =",p2.value())
#p0.mode(p0.IN) # TypeError: function takes 1 positional arguments but 2 were given
#p0.irq(lambda p:print(p))
p2.irq(lambda p:print(p)) # AttributeError: 'Pin' object has no attribute 'irq'
The new code is
Code: Select all
from pyb import Pin, ExtInt
import micropython
micropython.alloc_emergency_exception_buf(100)
red = Pin('X0', Pin.OUT)
sw = Pin('Y0', Pin.IN)
flag = False
def callback(line):
print('irq',line)
global flag
flag = True
ext = ExtInt(sw, ExtInt.IRQ_FALLING, Pin.PULL_UP, callback)
while True:
if flag:
flag = False
s = red.value()
if s:
red.value(0)
else:
red.value(1)
print('sw pressed')
I am just confused about differences between machine.Pin and pyb.Pin. I have tried the dir() to find the differences. From attribute list, there are no differences.
There is an extra question, Has pin.irq() method been removed officially?