Arduino 入门之小星星
原理:通过编号映射不同的频率音频信号,配合延时输出,达到演奏音乐和跑马灯的效果。
优酷视频链接:https://v.youku.com/v_show/id_XMzcxODQ4NjA3Mg==.html?spm=a2hzp.8244740.0.0
准备工作:Arduino开发板一块,串口线一根,电脑一台,Arduino ide,8欧喇叭一个,LED若干
#include "pitches.h"
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your Arduino model, check
the Technical Specs of your board at https://www.arduino.cc/en/Main/Products This example code is in the public domain. modified 8 May 2014
by Scott Fitzgerald modified 2 Sep 2016
by Arturo Guadalupi modified 8 Sep 2016
by Colby Newman
*/ int melody[] = {
NOTE_C4,NOTE_C4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4,NOTE_G4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_D4,NOTE_D4,NOTE_C4,NOTE_G4,NOTE_G4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_D4,NOTE_G4,NOTE_G4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_D4,NOTE_C4,NOTE_C4, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_A4,NOTE_G4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_D4,NOTE_D4,NOTE_C4
};
int noteDurations[] = {
, , , , , , , ,,,,,,,, , , , , , , ,,,,,,,, , , , , , , ,,,,,,
};
//bool btnstat=true;
//bool playing=true;
int dl=;
int pins[]={,,,};
// the setup function runs once when you press reset or power the board
void setup() {
//Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
for(int i=;i<;i++){
pinMode(pins[i], OUTPUT);
}
pinMode(, INPUT_PULLUP);
} //void setSwitch(){
// int stat=digitalRead(12);
// //Serial.println(stat);
// if(stat==0){
// if(btnstat){
// btnstat=false;
// }else{
// btnstat=true;
// }
// }
//}
// the loop function runs over and over again forever
void loop() {
int stat=digitalRead();
if(stat==) return;
for (int thisNote = ; thisNote < (sizeof(melody)/sizeof(int)); thisNote++) {
//setSwitch();
stat=digitalRead();
if(stat==) return;
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = / noteDurations[thisNote];
long led=random(,);
digitalWrite(pins[led], HIGH);
tone(, melody[thisNote], noteDuration); // to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
digitalWrite(pins[led], LOW);
// stop the tone playing:
noTone();
}
/*
for(int i=0;i<4;i++){
for(int j=0;j<3;j++){
digitalWrite(pins[i], HIGH); // turn the LED on (HIGH is the voltage level)
delay(dl); // wait for a second
digitalWrite(pins[i], LOW); // turn the LED off by making the voltage LOW
delay(dl);
}
//delay(200);
}
delay(500);
*/
}
Arduino 入门之小星星的更多相关文章
- Arduino入门套件 Arduino UNO R3
限时大抢购:原价5.6元超声波模块HC-SR04,现只需3元,亏本大甩卖,只赚人气,如需购买的客户请直接拍下以下链接3件=3元购买,备注超声波模块即可,每个客户ID每天仅限购一个.http://det ...
- Arduino入门学习
一直听到许多做物联网.智能家居的控制器使用的是Arduino,从师兄那里拿到了一块Arduino开发板,进行了一下午的学习,感觉这个适合小孩子们玩:) 废话少说,总结一下,便于以后可能会用得到.我主要 ...
- Arduino入门笔记(6):温度传感器及感温杯实验
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.Arduino板 :https://item.taob ...
- Arduino入门笔记(4):用蜂鸣器演奏音乐并配有LED闪烁
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.Arduino板 https://item.taoba ...
- Arduino入门笔记(3):单LED闪烁
转载请注明:@小五义http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 在搭建好arduino开发环境(http://www.cnblogs.com/xi ...
- Arduino入门笔记(1):认识Arduino
转载请注明:@小五义http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 各种网站论坛里经常看到网友DIY各种遥控小车.机器人什么的,一直很好奇,很想学习一 ...
- arduino入门套件学习过程-安装配置
arduino作为非常火的开源软硬件,有其巨大的优势和前景. 我呢,近期正好需要用arduino做一些小东西,借此机会,分享我的arduino学习历程,欢迎各位朋友一起讨论,指点! 现在进入正题: 这 ...
- nodejs操作arduino入门(javascript操作底层硬件)
用Javascript来操作硬件早就不是一件稀奇的事情了. 所以作为一名电子专业出身的FE,我也打算尝试一下用js来驱动arduino: 要想操作这些底层硬件,肯定是需要一些工具的,我这里介绍的工具主 ...
- Arduino入门笔记【1】
刚刚接触这个东西只知道这是类似于单片机的开发板,可以做一些单片机实现或者不能实现的东西,但是比单片机要简单得多. Arduino到底是什么? 维基百科上的描述是:Arduino是一块开发板的微控制器和 ...
随机推荐
- hdu 3466 Proud Merchants 01背包变形
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- Jvm性能监控和常用工具
JDK常用命令行工具 Jps : jps [options] [hostid] , -q 只显示jvmid, -m 传递给主类main的参数,-l 类全名,-v jvm启动参数 jstat : ...
- c# 获取文件夹大小
private long GetDirectorySizeMethod1(string directory) { long directorySize = 0; DirectoryInfo di = ...
- Java并发编程:深入剖析ThreadLocal (总结)
ThreadLocal好处 Java并发编程的艺术解释好处是:get和set方法的调用可以不用在同一个方法或者同一个类中. 问答形式总结: 1. ThreadLocal类的作用 ThreadLocal ...
- lib 和 dll
dll 和 lib只有在windows平台才会出现,老是忘记他们的区别和联系,记录一下,以备不时之需,也加深一下印象. 在弄懂两者的区别之前,需要知道两个概念: static library 和 d ...
- The method setItems(String) in the type ForTokensTag is not applicable for the arguments (Object)
1. 问题 看到这个错误以为是貌似jsp页面有误,c:forTokens标签用错了?? An error occurred at line: in the jsp file: /WEB-INF/pag ...
- jQuery Callback函数的用法
在动画100%完成后,调用callback函数 语法如下 $(selector).hide(speed, callback); <!-- html部分 --> <button> ...
- react native运行报错
更换RN项目目录位置后,react-native run-ios,出错. node_modules/react-native/ReactCommon/yoga/yoga/YGNodeList.c 解决 ...
- HTML 水平线hr
HTML 水平线 <hr /> 标签在 HTML 页面中创建水平线. hr 元素可用于分隔内容. 实例 <p>This is a paragraph</p> < ...
- T-SQL语法学习一(持续更新)
T-SQL语法学习(一) 第一节 不常用语句 不常用语句-指的是一些不常用的查询语句,不针对业务数据查询 SET STATISTICS IO ON(用于查询逻辑读取次数,物理读取次数) 图片 sele ...