文章标题
来源:互联网 发布:网购秒杀软件哪个好 编辑:程序博客网 时间:2024/06/15 04:32
toneAC Library for Arduino
When you send a tone to a speaker with the standard tone library, the loudest is at 50% duty cycle (only on half the time). Which at 5 volts, is like sending only 2.5v to the speaker. With toneAC, we’re sending out of phase signals on two pins. So in effect, the speaker is getting 5 volts instead of 2.5, making it nearly twice as loud.
Disadvantages are that it must use certain pins and it uses two pins instead of one.
It exclusively uses port registers for the fastest and smallest code possible.
http://playground.arduino.cc/Code/ToneAC
Syntax
toneAC( frequency [, volume [, length [, background ]]] ) - Play a note.
- frequency - Play the specified frequency indefinitely,
- turn off with toneAC().
-
- volume - [optional] Set a volume level(设置音量). (default: 10, range: 0 to 10 [0 = off])
- length - [optional] Set the length to play in milliseconds. (default: 0 [forever], range: 0 to 2^32-1)
-
- background - [optional] Play note in background or pause till finished? (default: false, values: true/false)
toneAC() - Stop output.
- background - [optional] Play note in background or pause till finished? (default: false, values: true/false)
void loop() { for (unsigned long freq = 150; freq <= 15000; freq += 10){ toneAC(freq); // Play the frequency (150 Hz to 15 kHz). delay(1); // Wait 1 ms so you can hear it. }
完整实例:
#include <toneAC.h>void setup() {} // Nothing to setup, just start playing!void loop() { for (unsigned long freq = 150; freq <= 15000; freq += 10){ toneAC(freq); // Play the frequency (150 Hz to 15 kHz). delay(1); // Wait 1 ms so you can hear it. } toneAC(0); // Turn off toneAC, can also use noToneAC(). while(1); // Stop.}
toneAC(steerFreq, 10, 0, true); // Output pulse for stepper
可以同于电机的输出频率上,
tone函数可以在一个输出引脚上输出一个方波。
noTone()停止方波
tone(4,500)即:第4个引脚输出500HZ的方波
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- poj-1019-Number Sequence【思维】【规律】
- 告诉你 Ubuntu 也可以这么玩
- SSM框架搭建
- rabbitmq Ubuntu下安装
- |洛谷|动态规划|P1968 美元汇率
- 文章标题
- UnsatisfiedLinkError: dlopen "/data/data/<package>/app_jni_lib/libxxx.so is 32-bit instead of 64-bit
- linux文件系统详解
- linux 下安装jdk并且配置环境变量
- ASimpleCache开源缓存框架使用之实现抽签小程序
- Coursera Machine Learning 第一周 引言(Introduction) quiz 习题答案
- 利用蚁群算法进行优化PID参数(个人总结)
- C语言中函数strlen等的实现
- 对象和数组:JVM中,处理对象和数组的字节码介绍