1 # SPDX-FileCopyrightText: 2024 Brent Rubell for Adafruit Industries
3 # SPDX-License-Identifier: MIT
4 import pytest # pylint: disable=unused-import
11 """Test analog output pin functionality."""
12 assert board.board_id == "OS_AGNOSTIC_BOARD"
13 pin_out = analogio.AnalogOut(board.Ax_OUTPUT)
15 # Test boundaries of setting the value and reading it back
17 assert pin_out.value == 0
19 assert pin_out.value == 65535
26 # Values for sine wave
27 # (data points = 20, amplitude=100, frequency=1)
51 # Values for a sawtooth wave
52 # (data points = 20, amplitude=100)
77 def test_Ax_INPUT_RAND_INT():
78 """Test random integer from pin Ax_INPUT_RAND_INT"""
79 assert board.board_id == "OS_AGNOSTIC_BOARD"
80 pin_random = analogio.AnalogIn(board.Ax_INPUT_RAND_INT)
82 assert isinstance(pin_random.value, int)
87 def test_Ax_INPUT_FIXED_INT_PI():
88 """Test fixed integer from pin Ax_INPUT_FIXED_INT_PI"""
89 assert board.board_id == "OS_AGNOSTIC_BOARD"
90 pin_pi = analogio.AnalogIn(board.Ax_INPUT_FIXED_INT_PI)
92 assert pin_pi.value == 31415
97 def test_Ax_INPUT_WAVE_SINE():
98 """Test sine wave from pin Ax_INPUT_WAVE_SINE"""
99 assert board.board_id == "OS_AGNOSTIC_BOARD"
100 pin_sine_wave = analogio.AnalogIn(board.Ax_INPUT_WAVE_SINE)
102 # Run through the sine wave once
103 for expected_value in sine_wave:
104 assert pin_sine_wave.value == expected_value
106 # Run through the sine wave again to ensure it loops back correctly
107 for expected_value in sine_wave:
108 assert pin_sine_wave.value == expected_value
110 pin_sine_wave.deinit()
113 def test_Ax_INPUT_WAVE_SAW():
114 """Test sawtooth wave from pin Ax_INPUT_WAVE_SAW"""
115 assert board.board_id == "OS_AGNOSTIC_BOARD"
116 pin_saw_wave = analogio.AnalogIn(board.Ax_INPUT_WAVE_SAW)
118 # Run through the sine wave once
119 for expected_value in sawtooth_wave:
120 assert pin_saw_wave.value == expected_value
122 # Run through the sine wave again to ensure it loops back correctly
123 for expected_value in sawtooth_wave:
124 assert pin_saw_wave.value == expected_value
126 pin_saw_wave.deinit()