周报

The Scientist 2018-11-15 06:06:21
第十一周学习周报
一 、本周学习情况
1、本周主要学习了利用蜂鸣器进行音乐制作
(1)编辑了音乐库 "pitches.h"
(2)完成了“生日快乐歌”的代码
2、学习制作温度计
二、学习笔记
制作音乐时,有源和无源的选择:
无源直接调整电平反转频率,发出不同声音,反转频率就是声音频率,严格来说没有上下限,反转多快频率多高。
无缘蜂鸣器可以通过控制器输出的pwm信号产生不同频率,
代码:
#include "pitches.h"

#include setup() {

void setup() {
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
}

void loop() {
ColorLight();
play();
delay(300);
}
int melody[] = {
NOTE_G4,//5
NOTE_G4,//5
NOTE_A4,//6
NOTE_G4,//5
NOTE_C5,//1.
NOTE_B4,//7
0,
NOTE_G4,//5
NOTE_G4,//5
NOTE_A4,//6
NOTE_G4,//5
NOTE_D5,//2.
NOTE_C5,//1.
digitalWrite(11, HIGH);
}

温度传感器0,
NOTE_G4,//5
NOTE_G4,//5
NOTE_G5,//5.
NOTE_E5,//3.
NOTE_C5,//1.
NOTE_B4,//7
NOTE_A4,//6
0,
NOTE_F5,//4.
NOTE_F5,//4.
NOTE_E5,//3.
NOTE_C5,//1.
NOTE_D5,//2.
NOTE_C5,//1.
0,
};


int noteDurations[] = {
8,8,4,4,4,4,
4,
8,8,4,4,4,4,
4,
8,8,4,4,4,4,2,
8,
8,8,4,4,4,2,
4,
};


void play()
{
for (int thisNote = 0; thisNote < 29; thisNote++) {

// 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 = 1000/noteDurations[thisNote];
tone(5, 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);
// stop the tone playing:
noTone(8);
}
}

void ColorLight()
{
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
为LM35,工作电压5V, 传感器类型:模拟
LM35的连接:VCC脚接5v,GND脚接面板包GND,Vout脚接Arduino模拟信号脚A0
从芯片平坦的一面看去,最左边的脚是VCC,最右边的脚是GND。
代码:
#include<LiquidCrystal.h>
int tmp=0; //模拟脚A0
int data;
int celsius;
LiquidCrystal lcd(12,11,5,4,3,2); //LCD构造函数
void setup()
{
lcd.begin(16,2);
lcd.print("the temperature");
lcd.setCursor(3,1);
lcd.print("is");
}

void loop()
{
lcd.setCursor(6,1);
data = analogRead(tmp); //获取温度传感器的值
celsius=(125*data)>>8; //计算温度的公式
lcd.print(celsius);
lcd.print((char)223);
lcd.print("C");
delay(2000); //两秒后刷新
}

三、下周学习计划
学习LiquidCrystal.h 库
基于51单片机蜂鸣器音乐的制作
四 存在问题
LiquidCrystal.h库函数的语法函数
如何提高温度的灵敏度
...全文
23 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

11,848

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧