Skip to content

Commit

Permalink
feat: you can now read an adc pin
Browse files Browse the repository at this point in the history
  • Loading branch information
boutreet committed Dec 11, 2023
1 parent 8b432ea commit 94e69e6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion leaphymicropython/utils/pins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from machine import Pin, PWM
from machine import Pin, PWM, ADC
from leaphymicropython.utils.boards_config import pin_to_gpio


Expand Down Expand Up @@ -49,3 +49,14 @@ def read_pin(pin: int) -> int:
pin = pin_to_gpio(pin)
pin = Pin(pin, Pin.IN)
return pin.value()


def read_adc(pin : int) -> int:
"""
reads an analog pin
:param pin: the pin to read
:return: returns the value
"""
pin = pin_to_gpio(pin)
adcpin = ADC(Pin(pin))
return adcpin.read_u16()

0 comments on commit 94e69e6

Please sign in to comment.