偉克多工作室--- Arduino DIY C 教學 ----快速 實驗 入門


<<最新消息 >>|<新書新品發表特價優惠> | 聯絡我們 |會員 | 檔案下載 | 訂購模組零件  訂購產品  回首頁  Line通訊ID avic8051


Arduino 學習參考書---無書自通Arduino實作入門與應用 ----松崗  詳細說明

Arduino基礎範例程式 

□再學不會用---  Arduino DIY 教學課程 1 1 教學----Line通訊ID avic8051------有問題 便可以發問,超方便


Arduino Uno相容控制板  Arduino說中文控制器  Arduino LCD顯示  Arduino超音波測距控制器


Arduino Uno相容控制板---VNO

_U1 (中型)_U11 (中型)

 

Arduino Uno相容控制板---VNO,有多重優點:

修改驅動程式,免除原Uno 插入不同板子,通訊埠COM 需要重新設定的麻煩驅動程式只需執行一次。

  連接VNO 板子前,先執行驅動程式SETUP.EXE,以後便可以輕易建立連線。

圖片 33

 

新增排針,方便與各型模組連接,不必插入麵包版,直接以杜邦線連模組

 控制器DIY超方便

新增2 按鍵,可以自行定義腳位,一個接高電位動作,一個接低電位動作。

int k1=7;  //設定按鍵1腳位 接高電位動作                                           

int k2=10; //設定按鍵2腳位  接低電位動作                                           

                                                       

void setup()//初始化設定                                           

{                                                      

  pinMode(led, OUTPUT);                                 

  pinMode(k1, INPUT);                                  

// digitalWrite(k1, HIGH);                              

  pinMode(k2, INPUT);                                  

  digitalWrite(k2, HIGH);                              

}    

 

void loop()//主程式                                            

{                                                      

char k1c, k2c;                                              

 led_bl();                                             

 while(1)                                               

  {                                                    

    k1c=digitalRead(k1); //偵測按鍵 1                               

    if(k1c==1)  led_bl();                              

                                                        

    k2c=digitalRead(k2); //偵測按鍵2                                

    if(k2c==0)  { led_bl();  led_bl(); }               

  }                                                    

}


□品名AR3_SA  Arduino說中文控制器

圖片 31

int led = 13; //設定LED腳位

int k1 =7; //設定按鍵腳位

int k2=10;

int gnd=19; //設定地線控制腳位

int v5=18; //設定5v控制腳位

int ck=14;int sd=15; int rdy=16; int rst=17; //設定語音合成控制腳位

 

// 中文big5 內碼,內容:語音合成 (產品中有中文big5 內碼轉換工具)

unsigned char m0[]={0xbb, 0x79, 0xad,0xb5, 0xa6, 0x58, 0xa6,0xa8,0};

unsigned char m1[]="ARDUIC";

unsigned char m2[]="0123456789";

 

void loop()//主程式 

{

char k1c,k2c,c; 

 reset(); led_bl();

 say(m0);  say(m1); //語音合成輸出

 while(1) //無窮

  {

     k1c=digitalRead(k1); //偵測按鍵有按鍵則語音合成輸出

     k2c=digitalRead(k2);

     if(k1c==1) { say(m1); led_bl(); }

     if(k2c==0) { say(m2); led_bl(); }

                                                   

  if (Serial.available() > 0) //偵測串口有信號傳入,則語音合成輸出

    {  c= Serial.read(); //有信號傳入                       

     if(c=='1') { say(m1);    led_bl();    }  

     if(c=='2') { say(m2);    led_bl();    }    

    }

  }

}


□品名AR3_LCD  Arduino LCD顯示

_LCD1 (中型)

Arduino在系統開發上經常會構建那些基本的I/O功能呢?大概可以分為以下幾種:

□按鍵輸入 LED動作指示燈□LCD液晶顯示器□喇叭或壓電喇叭□RS232串列介面

 

Arduino 常用 i/o 基本測試程式寫法,結合輸入輸出基本功能,來方便我們控制程式的開發。

若出現問題時,會再設計除錯程式進行錯。初學者善用這些程式,應該很容易進入Arduino

程式設計應用中,可以設計出自己想要的應用程式,或是控制器。

 

執行後,打開串列介面監控視窗,串列介面收到uno 傳來資料,LCD顯示訊息,

串列介面輸入指令傳到uno,反應如下:

*數字1¨LED 閃動2  *數字2¨LED 閃動4   *數字3¨LED 閃動6

 

按鍵k1 k2 按下反應如下:

*k1:壓電喇叭1    *k2:壓電喇叭2

 

#include <LiquidCrystal.h> //引用LCD程式庫                                                

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //設定 LCD 腳位                                    

int bz=8; //設定喇叭腳位                                                                  

int led = 13; /設定LED腳位                                                             

int k1 =7; //設定按鍵1腳位                                                                

int k2 =9; //設定按鍵2腳位                                                                

//--------------------------------------                                   

void setup() { //初始化設定                                                             

  lcd.begin(16, 2);                                                        

  lcd.print("hello, world1");                                              

                                                                            

  Serial.begin(9600);                                                      

  pinMode(led, OUTPUT);                                                    

  pinMode(bz, OUTPUT);                                                      

  digitalWrite(bz, LOW);                                                   

  pinMode(k1, INPUT); digitalWrite(k1, HIGH);                              

  pinMode(k2, INPUT); digitalWrite(k2, HIGH);                              

}                                                                           

//-----------------------------------                                      

void led_bl()//LED 閃動                                                              

{                                                                           

int i;                                                                     

 for(i=0; i<2; i++)                                                        

  {                                                                         

   digitalWrite(led, HIGH); delay(150);                                    

   digitalWrite(led, LOW);  delay(150);                                    

  }                                                                        

} 

                                                              

void be()//發出                                                                 

{                                                                          

int i;                                                                      

 for(i=0; i<100; i++)                                                      

  {                                                                        

   digitalWrite(bz, HIGH); delay(1);                                        

   digitalWrite(bz, LOW);  delay(1);                                       

  } 

 delay(100);

}                                                                          

//-----------------------------------                                       

void loop()//主程式                                                               

{                                                                          

boolean k1f, k2f;                                                          

char c;                                                                    

 led_bl(); be();                                                                

 Serial.print("uart test : "); 

  delay(1000);                                                               

 lcd.setCursor(0, 0);lcd.print("hello, world2");                           

 delay(1000);                                                              

 lcd.setCursor(0, 1);lcd.print("test line2");                              

while(1) //無窮                                                                 

  {                                                                        

  if (Serial.available() > 0) //有串列介面指令進入                                             

    {                                                                       

     c= Serial.read();//讀取串列介面指令                                                      

     if(c=='1')   {Serial.print("1 ");led_bl();}                           

     if(c=='2')   {Serial.print("2 ");led_bl();led_bl(); }                 

     if(c=='3')   {Serial.print("3 ");led_bl();led_bl(); led_bl();}        

    }

     k1f=digitalRead(k1); if(k1f==0)  be();     //掃描k1是否有按鍵                                  

     k2f=digitalRead(k2); if(k2f==0) { be(); be();}//掃描k2是否有按鍵                           

  }                                                                         

}


□品名AR3_SO  Arduino超音波測距控制器

_SO (中型)

量測前方物體距離的感知器,有許多方法,最普遍通用的方式,是使用超音波發射及接收配對的

感知器來設計,超音波測距一般應用如下:

□測距距離顯示

□前方距離偵測

□自動門開啟

□自走車避障

□防盜偵測應用

 

超音波模組動作時序圖

so2

Arduino 系統中已經內建函式計算高電位脈衝時間寬度,使用以下函數:

pulseIn(echo, HIGH);

測試echo 腳位,高電位脈衝時間寬度值為何。

傳回值單位為微秒 us

 

因此高電位脈衝時間寬度量測程式,可以設計如下:

unsigned long tco()                                    

{                                                       

//發出觸發信號

  digitalWrite(trig, HIGH); //設定高電位                            

  delayMicroseconds(10);  //延遲10 us                              

  digitalWrite(trig, LOW); //設定低電位                           

  return pulseIn(echo, HIGH); //傳回高電位脈衝時間寬度值                         

}

 

[控制電路]

圖片 24

 

#include <LiquidCrystal.h>//引用LCD程式庫                            

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //設定 lcd  腳位                  

int trig = 10;  //設定觸發腳位                                       

int echo = 9; //設定返回信號腳位                                         

float cm;  //設定返回信號腳位                                    

void setup()//初始化設定                                           

{                                                      

  Serial.begin(9600);                                  

  Serial.print("sonar test:");                         

  lcd.begin(16, 2);                                     

  lcd.print("AR SO measure");                          

  pinMode(trig, OUTPUT);                               

  pinMode(echo, INPUT);                                

}                                                      

                                                        

unsigned long tco() //高電位脈衝時間寬度量測                                   

{                                                      

  //發出觸發信號

  digitalWrite(trig, HIGH); //設定高電位                            

  delayMicroseconds(10);  //延遲10 us                              

  digitalWrite(trig, LOW); //設定低電位                           

  return pulseIn(echo, HIGH); //傳回量測結果 

}                                                      

                                                        

void loop()//主程式                                              

{                                                      

  cm=(float)tco()*0.017;//計算前方距離

  Serial.print(cm);  //串口顯示資料                                   

  Serial.println(" cm");                               

  lcd.setCursor(0, 1); 

  lcd.print("            ");

  lcd.setCursor(0, 1);

  lcd.print(cm,1); //LCD顯示資料

  lcd.print(" c m");                  

  delay(500);   

}


 

 


訂購產品  回首頁