Pin Class

Constructor

Creates and initializes a pin.

pin = Pin(board, vpin, mode)
  • board: The board object created by the PinPong class. This parameter can be omitted if there is only one board.
  • vpin: The pin number used on the board. (Digital pin 1 - Pin.D1, Analog pin 1 - Pin.A1)
  • mode: Defines the input or output of the pin. Pin.IN, Pin.OUT (When defining an analog pin, this can be omitted and defaults to input)

For example, to define a digital input such as a button,

button_pin = Pin(Pin.D8, Pin.IN)

To define an analog sensor pin,

Analog_pin = Pin(Pin.A0)

Methods

pin.value()
When called with no arguments, it performs a digital read, returning 0 or 1.
v = button_pin.value()  # Get the state of pin button_pin
pin.value(x)
When called with an argument, it performs a digital write.
pin.value(1)  # Set pin to high level
pin.on()
Sets the pin to high level, equivalent to pin.value(1).
pin.off()
Sets the pin to low level, equivalent to pin.value(0).
pin.irq(trigger, handler)
Sets an interrupt.
- trigger: Interrupt mode, rising - rising edge, falling - falling edge, low - low level, high - high level...
- handler: The function to be called when the interrupt is triggered.