1 # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
3 # SPDX-License-Identifier: MIT
5 `analogio` - Analog input and output control
6 =================================================
7 See `CircuitPython:analogio` in CircuitPython for more details.
8 * Author(s): Carter Nelson
11 from adafruit_blinka.microcontroller.nxp_lpc4330.pin import Pin
12 from adafruit_blinka import ContextManaged
15 class AnalogIn(ContextManaged):
16 """Analog Input Class"""
18 def __init__(self, pin):
19 self._pin = Pin(pin.id)
20 self._pin.init(mode=Pin.ADC)
24 """Read the ADC and return the value"""
25 return self._pin.value()
27 # pylint: disable=no-self-use
29 def value(self, value):
30 # emulate what CircuitPython does
31 raise AttributeError("'AnalogIn' object has no attribute 'value'")
33 # pylint: enable=no-self-use
39 class AnalogOut(ContextManaged):
40 """Analog Output Class"""
42 def __init__(self, pin):
43 self._pin = Pin(pin.id)
44 self._pin.init(mode=Pin.DAC)
48 """Return an error. This is output only."""
49 # emulate what CircuitPython does
50 raise AttributeError("unreadable attribute")
53 def value(self, value):
54 self._pin.value(value)