Simple tests

Ensure your device works with these simple tests.

examples/simpleio_tone_demo.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5'tone_demo.py'.
 6
 7=================================================
 8a short piezo song using tone()
 9"""
10import time
11import board
12import simpleio
13
14
15while True:
16    for f in (262, 294, 330, 349, 392, 440, 494, 523):
17        simpleio.tone(board.A0, f, 0.25)
18    time.sleep(1)
examples/simpleio_shift_in_out_demo.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5'shift_in_out_demo.py'.
 6
 7=================================================
 8shifts data into and out of a data pin
 9"""
10
11import time
12import board
13import digitalio
14import simpleio
15
16# set up clock, data, and latch pins
17clk = digitalio.DigitalInOut(board.D12)
18data = digitalio.DigitalInOut(board.D11)
19latch = digitalio.DigitalInOut(board.D10)
20clk.direction = digitalio.Direction.OUTPUT
21latch.direction = digitalio.Direction.OUTPUT
22
23while True:
24    data_to_send = 256
25    # shifting 256 bits out of data pin
26    latch.value = False
27    data.direction = digitalio.Direction.OUTPUT
28    print("shifting out...")
29    simpleio.shift_out(data, clk, data_to_send, msb_first=False)
30    latch.value = True
31    time.sleep(3)
32
33    # shifting 256 bits into the data pin
34    latch.value = False
35    data.direction = digitalio.Direction.INPUT
36    print("shifting in...")
37    simpleio.shift_in(data, clk)
38    time.sleep(3)
examples/simpleio_map_range_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5'map_range_demo.py'.
 6
 7=================================================
 8maps a number from one range to another
 9"""
10import time
11import simpleio
12
13while True:
14    sensor_value = 150
15
16    # Map the sensor's range from 0<=sensor_value<=255 to 0<=sensor_value<=1023
17    print("original sensor value: ", sensor_value)
18    mapped_value = simpleio.map_range(sensor_value, 0, 255, 0, 1023)
19    print("mapped sensor value: ", mapped_value)
20    time.sleep(2)
21
22    # Map the new sensor value back to the old range
23    sensor_value = simpleio.map_range(mapped_value, 0, 1023, 0, 255)
24    print("original value returned: ", sensor_value)
25    time.sleep(2)