openmv/scripts/examples/50-Arduino-Boards/Portenta-H7/50-Board-Control/dac_write_timed.py
iabdalkader 98a29e0870 scripts/examples: Update examples.
- Add examples index.
- Remove RP2040's Bluetooth examples.
- Resort examples.
2023-10-29 21:21:55 +01:00

20 lines
561 B
Python

# This work is licensed under the MIT license.
# Copyright (c) 2013-2023 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# DAC Timed Write Example
#
# This example shows how to use the DAC pin output onboard your OpenMV Cam.
import math
from pyb import DAC
# create a buffer containing a sine-wave
buf = bytearray(100)
for i in range(len(buf)):
buf[i] = 128 + int(127 * math.sin(2 * math.pi * i / len(buf)))
# output the sine-wave at 400Hz
dac = DAC("P6")
dac.write_timed(buf, 400 * len(buf), mode=DAC.CIRCULAR)