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 in range(len(sine_wave)):
103 assert pin_sine_wave.value == sine_wave[i]
105 # Run through the sine wave again to ensure it loops back correctly
106 for i in range(len(sine_wave)):
107 assert pin_sine_wave.value == sine_wave[i]
109 pin_sine_wave.deinit()
112 def test_Ax_INPUT_WAVE_SAW():
113 """Test sawtooth wave from pin Ax_INPUT_WAVE_SAW"""
114 assert board.board_id == "GENERIC_AGNOSTIC_BOARD"
115 pin_sine_wave = analogio.AnalogIn(board.Ax_INPUT_WAVE_SAW)
117 # Run through the sine wave once
118 for i in range(len(sawtooth_wave)):
119 assert pin_sine_wave.value == sawtooth_wave[i]
121 # Run through the sine wave again to ensure it loops back correctly
122 for i in range(len(sawtooth_wave)):
123 assert pin_sine_wave.value == sawtooth_wave[i]
125 pin_sine_wave.deinit()