// 2017/6/20 // Faya-Nugget 範例程式 (GearedMotor_1.ino) // 單元: 模組介紹-faya減速馬達模組 // 網址: http://fayalab.blogspot.com/2017/06/fayagearedmotor.html // 目標: (1) 自走車自動前進3秒鐘 // (2) 停頓1秒 // (3) 自走車自動後退3秒鐘回到原來位置 // 接線: Arduino ==> faya模組 // D11 ==> SIG (減速馬達) // D12 ==> DIR (減速馬達) // D6 ==> SIG (減速馬達) // D7 ==> DIR (減速馬達) #define Wheel_R_DIR 12 #define Wheel_R_SIG 11 #define Wheel_L_DIR 7 #define Wheel_L_SIG 6 void setup() { pinMode(Wheel_R_DIR,OUTPUT); //右輪方向腳位 pinMode(Wheel_R_SIG,OUTPUT); //右輪速度腳位 pinMode(Wheel_L_DIR, OUTPUT); //左輪方向腳位 pinMode(Wheel_L_SIG, OUTPUT); //左輪速度腳位 StopMove(); //停止走動 } void loop() { Forward(); delay(3000); StopMove(); delay(1000); Backward(); delay(3000); StopMove(); while(1); } void Forward() //前進 { digitalWrite(Wheel_R_DIR,LOW); analogWrite(Wheel_R_SIG,200); digitalWrite(Wheel_L_DIR,HIGH); analogWrite(Wheel_L_SIG,200); } void Backward() //後退 { digitalWrite(Wheel_R_DIR,HIGH); analogWrite(Wheel_R_SIG,200); digitalWrite(Wheel_L_DIR,LOW); analogWrite(Wheel_L_SIG,200); } void StopMove() //副程式 - 停止走動 { digitalWrite(Wheel_R_DIR,LOW); analogWrite(Wheel_R_SIG,0); digitalWrite(Wheel_L_DIR,LOW); analogWrite(Wheel_L_SIG,0); }