九鼎创展论坛中文版English
登录 | 立即注册 设为首页收藏本站 切换到宽版
查看: 4293|回复: 0

arduino ibox项目实战16-tonekeyboard实验

[复制链接]
发表于 2014-10-28 09:29:51 | 显示全部楼层 |阅读模式
硬件平台:PC机一台,ibox卡片电脑一只,arduino扩展板一个,喇叭或蜂鸣器一个
软件平台:WIN7操作系统,android4.0android4.4系统
实验目标:通过iboxPWM口控制喇叭或蜂鸣器实现报警鸣叫的功能。
打开arduino的IDE开发工具,依次点击文件->示例->02.Digital->toneKeyboard,toneKeyboard的示例程序将会被打开,其源码如下:
  1. #include "pitches.h"

  2. const int threshold = 10;    // minimum reading of the sensors that generates a note

  3. // notes to play, corresponding to the 3 sensors:
  4. int notes[] = {
  5.   NOTE_A4, NOTE_B4, NOTE_C3
  6. };

  7. void setup() {
  8. }

  9. void loop() {
  10.   for (int thisSensor = A0; thisSensor < A3; thisSensor++) {
  11.     // get a sensor reading:
  12.     int sensorReading = analogRead(thisSensor);

  13.     // if the sensor is pressed hard enough:
  14.     if (sensorReading > threshold) {
  15.       // play the note corresponding to this sensor:
  16.       tone(PWM0, notes[thisSensor - A0], 20);
  17.       delay(20);
  18.     }
  19.   }
  20. }
复制代码
       将喇叭或蜂鸣器通过杜绑线接到ibox扩展板的PWM口,点击上传按钮运行程序,喇叭或蜂鸣器将会不断鸣叫。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|深圳市九鼎创展科技官方论坛 ( 粤ICP备11028681号-2  

GMT+8, 2024-6-14 23:53 , Processed in 0.019763 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表