"""
Author: Dacadev
Description: Script to show how the Pin clase works and how use it with micropython.
This code was made for the raspberry pico (RP2040)
"""
from machine import Pin
from utime import sleep
# Basic usage
led_1 = Pin(0, Pin.OUT, value=True)
# Init after create instance
led_2 = Pin(4)
led_2.init(Pin.OUT, value=True)
# Use pin in and pin out
btn_1 = Pin(17, Pin.IN, pull=Pin.PULL_UP)
led_3 = Pin(22)
led_3.init(Pin.OUT, pull=Pin.PULL_DOWN, value=False)
# Configure an interrupt
btn_2 = Pin(16, Pin.IN, pull=Pin.PULL_UP)
led_4 = Pin(21, Pin.OUT, pull=Pin.PULL_DOWN, value=True)
def callback(pin):
led_4.toggle()
btn_2.irq(callback, Pin.IRQ_RISING)
while True:
sleep(.5)
led_1.toggle()
led_3.value(btn_1.value())
if led_1.value():
led_2.toggle()
pico:GP0
pico:GP1
pico:GND.1
pico:GP2
pico:GP3
pico:GP4
pico:GP5
pico:GND.2
pico:GP6
pico:GP7
pico:GP8
pico:GP9
pico:GND.3
pico:GP10
pico:GP11
pico:GP12
pico:GP13
pico:GND.4
pico:GP14
pico:GP15
pico:GP16
pico:GP17
pico:GND.5
pico:GP18
pico:GP19
pico:GP20
pico:GP21
pico:GND.6
pico:GP22
pico:RUN
pico:GP26
pico:GP27
pico:GND.7
pico:GP28
pico:ADC_VREF
pico:3V3
pico:3V3_EN
pico:GND.8
pico:VSYS
pico:VBUS
led1:A
led1:C
r1:1
r1:2
r2:1
r2:2
gnd1:GND
gnd2:GND
led2:A
led2:C
sw1:1
sw1:2
sw1:3
vcc2:VCC
sw2:1
sw2:2
sw2:3
led4:A
led4:C
led3:A
led3:C