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是一块开发板的微控制器和 ...
随机推荐
- ApplicationContextAware接口
在某些特殊的情况下,Bean需要实现某个功能,但该功能必须借助于Spring容器才能实现,此时就必须让该Bean先获取Spring容器,然后借助于Spring容器实现该功能.为了让Bean获取它所在的 ...
- 自定义控件实现-今日头条Android APP图集效果
前提 产品有个新需求,类似今日头条的图集效果 大致看了下UI,大致就是ViewPager,横向滑动切换图片,纵向滑动移动图片,纵向超过一定距离,图片飞出,图集淡出动画退出,支持图片的双击放大. 思路 ...
- python logging的应用
#-*-coding:utf-8-*-#util import logging import logging from logging.handlers import RotatingFileHand ...
- 浮动的补充丶文本和字体属性丶background丶定位
一丶浮动的补充 浮动的特性: 1. 浮动的元素脱标 2.浮动的元素互相贴靠 3.浮动的元素有"字围"效果 4.浮动的元素有收缩的效果 前提是标准文档流,margin的垂直方向会出现 ...
- 1-3 Sass 语法、编译、调试
Sass 语法格式 这里说的 Sass 语法是 Sass 的最初语法格式,他是通过 tab 键控制缩进的一种语法规则,而且这种缩进要求非常严格.另外其不带有任何的分号和大括号.常常把这种格式称为 Sa ...
- css3阴影
<!DOCTYPE html> <html> <head> <style> div { margin-top:100px; margin-left:10 ...
- ERP与电子商务的集成
目前现状: 一般来说,企业中存在三种流:物资流.资金流和信息流,其中,信息流不是孤立存在的,它与物资流和资金流密切相关,反映了物资和资金流动前.流动中和流动后的状况. 电子商务与ERP被分裂开来,没有 ...
- Java集合排序
[ 1.对普通的包装类基本数据类型的list数组排序(Integer,Long,Double) ] Collections.sort(List list) [例] List<Long> m ...
- 【OBJC】数字转中文大写
博客园都不知道怎么外链图片…… - (void)numToString:(double)num{ ; NSMutableString *szChMoney = [[NSMutableString al ...
- tempdb过大事故记录-sqlserver
今天收到预警消息,提示磁盘空间已经满了,感觉很奇怪.刚装的新机器怎么可能会磁盘空间不足.登陆看了看 可以看的到tempdb已经65G的了,而且显示是百分百可用.这个就很奇怪了,为什么会出现这种情况呢. ...