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是一块开发板的微控制器和 ...
随机推荐
- javascript bind在回调中精简匿名函数的用法
常规写法: Promise对象回调,匿名函数调用其他方法 更精简的写法: 注:这种写法的使用有两个严苛的限制. 1.回调的结果必须放在实际调用方法参数的最后一位: 2.回调函数中只调用其他一个方法.
- 全面理解Java内存模型(JMM)及volatile关键字(转)
原文地址:全面理解Java内存模型(JMM)及volatile关键字 关联文章: 深入理解Java类型信息(Class对象)与反射机制 深入理解Java枚举类型(enum) 深入理解Java注解类型( ...
- thinkphp多表联合查询
1.两个表查询 $userid=session('user.id'); $user = M('cuser'); $data = $user->field('projectno')->whe ...
- 第1章 初识CSS3
什么是CSS3? CSS3是CSS2的升级版本,3只是版本号,它在CSS2.1的基础上增加了很多强大的新功能. 目前主流浏览器chrome.safari.firefox.opera.甚至360都已经支 ...
- Scrapy框架的使用
Scrapy框架的安装 pip install pywin32 下载 Twisted 包 pip install Twisted包的路径 pip insatll scrapy Scrapy ...
- [ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:unpack (unpack) on project sq-integral-web: Unable to find artifact.
1.问题描述 项目maven打包报上述错误, 但是小伙伴运行好使. 2.问题解决 是idea工程编码(gbk)和项目编码(utf-8)不一致 idea->file->Other Setti ...
- js权威指南学习笔记(二)表达式与运算符
1.数组初始化表达式 数组直接量中的列表逗号之间的元素可以省略,这时省略的空位会填充undefined.如: 2 2 1 var arr = [1,,,,,6]; 2 ...
- 阿里云更懂你的数据库,免费提供DBA服务
阿里云更懂你的数据库,免费提供DBA服务 阿里云云数据库(RDS)管理控制台近期将全面升级为云数据库管家.云数据库管家的使命是提供便捷的操作.贴心的服务.专业的处理建议,帮助用户管理好云数据库. ...
- python shopping incomplete code
#shopping code#shopping.py#导入登录模块import login# shop car beginningsalary = input("请输入工资:\t" ...
- Infragist ics Ult imate 2015 Vol.1 - Product Keys
Ultimate ProductKeys 2015 Vol.1: 9122-1900164-4504144 9122-9300855-3994197 9122-7600717-4579130 9122 ...