A.先接好溫控,並測試
溫控
int tempr=A0;
int tv=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
tv=analogRead(tempr);
Serial.println(tv);
delay(2000);
}
=============================
兩顆七段顯示器可正常運作
int sp1[10][7]={{1,1,1,1,1,1,0},{0,1,1,0,0,0,0},{1,1,0,1,1,0,1},{1,1,1,1,0,0,1},{0,1,1,0,0,1,1},{1,0,1,1,0,1,1},{1,0,1,1,1,1,1},{1,1,1,0,0,0,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}};
int sp2[10][7]={{1,1,1,1,1,1,0},{0,1,1,0,0,0,0},{1,1,0,1,1,0,1},{1,1,1,1,0,0,1},{0,1,1,0,0,1,1},{1,0,1,1,0,1,1},{1,0,1,1,1,1,1},{1,1,1,0,0,0,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}};
int k=0;
int k2=0;
void setup() {
// put your setup code here, to run once:
for(int i=0;i<=13;i++)
{
pinMode(i,OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
for(int j=0;j<7;j++)
{
digitalWrite(j,sp1[k][j]);
}
for(int h=7;h<=13;h++)
{
digitalWrite(h,sp2[k2][h]);
}
delay(2000);
k++;
k2++;
if(k==10)
{
k=0;
}
if(k2==10)
{
k2=0;
}
}
=================================
C.再接上 溫控及讀取其值顯示在七段顯示器
int sp1[10][7]={{1,1,1,1,1,1,0},{0,1,1,0,0,0,0},{1,1,0,1,1,0,1},{1,1,1,1,0,0,1},{0,1,1,0,0,1,1},{1,0,1,1,0,1,1},{1,0,1,1,1,1,1},{1,1,1,0,0,0,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}};
int sp2[10][7]={{1,1,1,1,1,1,0},{0,1,1,0,0,0,0},{1,1,0,1,1,0,1},{1,1,1,1,0,0,1},{0,1,1,0,0,1,1},{1,0,1,1,0,1,1},{1,0,1,1,1,1,1},{1,1,1,0,0,0,0},{1,1,1,1,1,1,1},{1,1,1,1,0,1,1}};
int tempr=A0;
int tv=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
for(int i=0;i<=13;i++)
{
pinMode(i,OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
tv=analogRead(tempr);
Serial.println(tv);
String sdata=(String)tv;
int k=sdata.charAt(0)-'0';
int k2=sdata.charAt(1)-'0';
for(int j=0;j<7;j++)
{
digitalWrite(j,sp1[k][j]);
}
for(int h=7;h<=13;h++)
{
digitalWrite(h,sp2[k2][h]);
}
delay(2000);
k++;
k2++;
if(k==10)
{
k=0;
}
if(k2==10)
{
k2=0;
}
}
======================================
光敏電阻 控制LED燈
int lightr=A0;
int vin=0;
int refv=850; //視實際光度
int led=7;
void setup() {
// put your setup code here, to run once:
pinMode(led,OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
vin=analogRead(lightr);
Serial.println(vin);
if (vin>refv)
{
digitalWrite(led,LOW);
}
if (vin<refv)
{
digitalWrite(led,HIGH);
}
}
=================================================
#difine 定義
1.定義接腳
2.定義運算式
3.定義函數
#define 名稱 資料
沒有留言:
張貼留言