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