九鼎创展论坛
标题: arduino ibox项目实战16-tonekeyboard实验 [打印本页]
作者: armeasy 时间: 2014-10-28 09:29
标题: arduino ibox项目实战16-tonekeyboard实验
硬件平台:PC机一台,ibox卡片电脑一只,arduino扩展板一个,喇叭或蜂鸣器一个
软件平台:WIN7操作系统,android4.0或android4.4系统
实验目标:通过ibox的PWM口控制喇叭或蜂鸣器实现报警鸣叫的功能。
打开arduino的IDE开发工具,依次点击文件->示例->02.Digital->toneKeyboard,toneKeyboard的示例程序将会被打开,其源码如下:
- #include "pitches.h"
-
- const int threshold = 10; // minimum reading of the sensors that generates a note
-
- // notes to play, corresponding to the 3 sensors:
- int notes[] = {
- NOTE_A4, NOTE_B4, NOTE_C3
- };
-
- void setup() {
- }
-
- void loop() {
- for (int thisSensor = A0; thisSensor < A3; thisSensor++) {
- // get a sensor reading:
- int sensorReading = analogRead(thisSensor);
-
- // if the sensor is pressed hard enough:
- if (sensorReading > threshold) {
- // play the note corresponding to this sensor:
- tone(PWM0, notes[thisSensor - A0], 20);
- delay(20);
- }
- }
- }
复制代码 将喇叭或蜂鸣器通过杜绑线接到ibox扩展板的PWM口,点击上传按钮运行程序,喇叭或蜂鸣器将会不断鸣叫。
欢迎光临 九鼎创展论坛 (http://bbs.9tripod.com/) |
Powered by Discuz! X3.2 |