极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 16895|回复: 2

[翻译]]Arduino自带范例Digital之tonekeyboard

[复制链接]
发表于 2012-11-18 21:47:29 | 显示全部楼层 |阅读模式
本帖最后由 弘毅 于 2012-11-19 17:39 编辑

  1. /*
  2.   keyboard
  3. 播放声音的音调变化是随着模拟量输入的变化而改变


  4. 电路描述:
  5. *3 个模拟传感器 接+5V从模拟口A0至A5
  6. *3 个10K电阻从模拟口A0至A5回到GND
  7. *8欧姆的杨声器接在数字端口8
  8. created 21 Jan 2010
  9. modified 9 Apr 2012
  10. by Tom Igoe

  11. 这个范例代码在公共范围(不受版权制约)

  12. http://arduino.cc/en/Tutorial/Tone3

  13. */
  14. /*
  15. 电路原理图

  16. */


  17. #include "pitches.h"

  18. const int threshold = 10;    // 传感器的最小读数
  19. //notes数组包含三个传感器,用于播放
  20. int notes[] = {
  21.   NOTE_A4, NOTE_B4,NOTE_C3 };

  22. void setup() {

  23. }

  24. void loop() {
  25.   for (int thisSensor = 0; thisSensor < 3; thisSensor++) {

  26.     //得到一个传感器的读数
  27.     int sensorReading = analogRead(thisSensor);


  28.     //如果传感器被按下足够了
  29.     if (sensorReading > threshold) {
  30.       // play the note corresponding to this sensor:
  31.       //播放对应的传器器相应的声音
  32.       tone(8, notes[thisSensor], 20);
  33.     }
  34.   }
  35. }

复制代码


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2012-11-18 23:11:18 | 显示全部楼层
我觉得。。。这个用按钮足矣。。。这个触摸传感器太高端了。。
回复 支持 反对

使用道具 举报

发表于 2012-11-18 23:55:16 | 显示全部楼层
那些压力传感器貌似很贵~~~
不过还是很有意思的设计
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 05:15 , Processed in 0.044894 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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