1 # SPDX-FileCopyrightText: 2024 Brent Rubell for Adafruit Industries
3 # SPDX-License-Identifier: MIT
10 """Test analog output pin functionality."""
11 assert board.board_id == "GENERIC_AGNOSTIC_BOARD"
12 pin_out = analogio.AnalogOut(board.Ax_OUTPUT)
14 # Test boundaries of setting the value and reading it back
16 assert pin_out.value == 0
18 assert pin_out.value == 65535
25 # Values for sine wave
26 # (data points = 20, amplitude=100, frequency=1)
50 # Values for a sawtooth wave
51 # (data points = 20, amplitude=100)
76 def test_Ax_INPUT_RAND_INT():
77 """Test random integer from pin Ax_INPUT_RAND_INT"""
78 assert board.board_id == "GENERIC_AGNOSTIC_BOARD"
79 pin_random = analogio.AnalogIn(board.Ax_INPUT_RAND_INT)
81 assert isinstance(pin_random.value, int)
86 def test_Ax_INPUT_FIXED_INT_PI():
87 """Test fixed integer from pin Ax_INPUT_FIXED_INT_PI"""
88 assert board.board_id == "GENERIC_AGNOSTIC_BOARD"
89 pin_pi = analogio.AnalogIn(board.Ax_INPUT_FIXED_INT_PI)
91 assert pin_pi.value == 31415
96 def test_Ax_INPUT_WAVE_SINE():
97 """Test sine wave from pin Ax_INPUT_WAVE_SINE"""
98 assert board.board_id == "GENERIC_AGNOSTIC_BOARD"
99 pin_sine_wave = analogio.AnalogIn(board.Ax_INPUT_WAVE_SINE)
101 # Run through the sine wave once
102 for i, expected_value in enumerate(sine_wave):
103 assert pin_sine_wave.value == expected_value
106 # Run through the sine wave again to ensure it loops back correctly
107 for i, expected_value in enumerate(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 == "GENERIC_AGNOSTIC_BOARD"
116 pin_saw_wave = analogio.AnalogIn(board.Ax_INPUT_WAVE_SAW)
118 # Run through the sine wave once
119 for i in range(len(sawtooth_wave)):
120 assert pin_saw_wave.value == sawtooth_wave[i]
122 # Run through the sine wave again to ensure it loops back correctly
123 for i in range(len(sawtooth_wave)):
124 assert pin_saw_wave.value == sawtooth_wave[i]
127 pin_saw_wave.deinit()