Arduino应用范例10例讲解Word文档格式.docx
《Arduino应用范例10例讲解Word文档格式.docx》由会员分享,可在线阅读,更多相关《Arduino应用范例10例讲解Word文档格式.docx(12页珍藏版)》请在冰豆网上搜索。
7工
厂顺序启动反顺序停车控制系统9
8楼
道声光控灯10
9水
塔自动上水装置11
10电
机拖动控制12
1・趣味彩灯
for(int
•r\•/•・・、//
pinMode(i,INPUT);
for(intj二8;
j〈二13;
j++)
//pinMode(j,OUTPUT);
voidloop()
(
if(digita.lRead(l)==HIGH)
{
if(digitalRead(l)==HI
GH)
for(intx=9;
x<
=12:
x++)//
digitalWrite(x,HIGH);
delay(1000);
}
delay(10000);
rlinri++o(vTAW、•
把0-7设置为
把8-13设置为输出
循环方式依次让每个led在1秒内点亮
循环方式依次让每个led熄灭
循环10次,亮0.5秒灭0.5秒,共10秒
digitalWrite(13,HIGH);
delay(500);
digitalWrite(13,LOW);
2.楼道延时报警灯
voidsetup()
for(inti二0,j二9;
i〈二&
j〈二13;
i++,j++)//设置0-8为输入,9-13为输出{pinMode(i,INPUT);
pinMode(j,OUTPUT);
)
if(digitalRead(l)==HIGH|digitalRead
(2)==HIGH)//引脚1或2置高电平{亠
digitalWrite(9,HIGH);
//9置高电平delay(25000);
//延时25秒digitalWrite(10,HIGH);
//10置高电平
delay(5000);
//延时5秒
digitalWrite(10,LOW);
//10置低电平
digitalWrite(9,LOW):
//9置低电平
厂
3•行程自动往返工件传送带
把0-7设置为输入
for(inti二0;
i〈二7;
i++)//pinMode(i,INPUT);
j++)//pinMode(j,OUTPUT):
voidloop(){
if(digitalRead(l)==HIGH){digitalWrite(9,HIGH);
digitalWrite(10,LOW);
}
if(digitalRead
(2)==HIGH){digitalWrite(10,HIGH);
digitalWrite(9,LOW);
if(digitalRead(3)==HIGH){digitalWrite(9,LOW);
digitalWrite(10,LOW);
4.A、B>
C三路智能抢答器(直接用带闪烁灯的蜂鸣器更好)
需蔦」;
霊羔囂囂茫爲r设置°
-8为输入为输出
{if(digitalRead(l)==HIGH&
&
digitalRead(11)==L0W&
digitalRead(13)==L0W){
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
if(digitalRead
(2)==HIGH&
digitalRead(9)==LOW&
digitalRead(13)==L0W)
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
if(digitalRead(3)==HIGH&
digitalRead(11)==L0W)(digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
if(digitalRead(4)==HIGH)for(intk=8;
k<
=13;
k++)digitalWrite(k,LOW);
5.机床控制系统
一口:
干磺开关接近开关X2气"
voidsetupQ
{pinMode(j,OUTPUT);
}}voidloop()
for(inti二0;
i++){pinMode(i,INPUT):
}for(intj二8;
j++)//{digitalWrite(9,digitalRead(l));
digitalWrite(10,!
digitalRead
(2));
digitalWrite(11,digitalRead(3));
1
6.楼上楼下共控一灯(方式2)
设置0-8为输入,9-13为
输岀
灯Y9
有按键按下
延时去抖动
的状态翻转
等待按键松手
voidsetup()
for(inti=0,j=9;
i<
=8,j<
i++,j++)
//
■/〒亠41{pinMode(i,INPUT);
}>
voidloop(){
if(digitalRead(l)二二HIGH)//
delay(20):
//if(digitalRead
(1)二二HIGH)//{
digitalWrite(9,!
digitalRead(9));
//LEDwhile(digitalRead
(1)==HIGH):
//
if(digitalRead
(2)==HIGH)//
//if(digitalRead
(2)二二HIGH)//{
digita.lRead(9)):
//LEDwhile(digitalRead
(2)二二HIGH);
//}
的状态翻转等待按键松
电机
7.
工厂顺序启动反顺序停车控制系统
{pinMode(j,OUTPUT);
voidloopO{if(digitalRead(l)==HIGH){digitalWrite(9,HIGH):
delay(5000);
}if(digitalRead
(2)==HIGH){digitalWrite(10,LOW);
delay(5000);
8.楼道声光控灯
for(inti二0;
i〈二7;
i++)//把0-7设置为输入{pinMode(i,INPUT);
}for(intj二8;
j〈二13;
j++)//把8-13设置另输岀{pinMode(j,OUTPUT);
voidloopO{if(digitalRead
(1)==HIGH&
digitalRead
(2)==HIGH){digitalWrite(9,HIGH);
delay(20000);
9.水塔自动上水装置
voidsetup(){pinMode(l,INPUT):
pinMode(9,OUTPUT);
}voidloop(){digitalWrite(9,!
digitalRead
(1));
11.电机拖动控制
i++)//把0-7设置为输入pinMode(i,INPUT);
for(intj二8;
j++)//把8-13设置头/输出pinMode(j,OUTPUT);
if(digitalRead(l)==HIGH&
digitalRead(9)==L0W&
digitalRead(10)==L0W)<
digitalWrite(9,HIGH);
delay(5000);
I
if(digitalRead
(2)==HIGH)
{digitalWrite(9,HIGH);
}if(digitalRead(3)==HIGH)
{digitalWrite(9,LOW);
}if(digitalRead(4)==HIGH)
{digitalWrite(10,HIGH);
}if(digitalRead(5)==HIGH)
{digitalWrite(10,LOW);