| 
 | 
 
我要做一個藍芽自走車,以下次我的程式: 
int MotorRight1=5; 
int MotorRight2=6; 
int MotorLeft1=10; 
int MotorLeft2=11; 
 
 
void setup() 
{   
  Serial.begin(9600); 
  pinMode(MotorRight1, OUTPUT);  // 腳位 8 (PWM) 
  pinMode(MotorRight2, OUTPUT);  // 腳位 9 (PWM) 
  pinMode(MotorLeft1,  OUTPUT);  // 腳位 10 (PWM)  
  pinMode(MotorLeft2,  OUTPUT);  // 腳位 11 (PWM) 
} 
 
void go()// 前進 
{ 
        digitalWrite(MotorRight1,LOW); 
        digitalWrite(MotorRight2,HIGH); 
        digitalWrite(MotorLeft1,LOW); 
        digitalWrite(MotorLeft2,HIGH); 
 
} 
 
void left() //右轉 
{ 
      digitalWrite(MotorRight1,HIGH); 
      digitalWrite(MotorRight2,LOW); 
      digitalWrite(MotorLeft1,LOW); 
      digitalWrite(MotorLeft2,HIGH); 
 
} 
void right() //左轉 
{ 
      digitalWrite(MotorRight1,LOW); 
      digitalWrite(MotorRight2,HIGH); 
      digitalWrite(MotorLeft1,HIGH); 
      digitalWrite(MotorLeft2,LOW); 
 
}  
void stop() //停止 
{ 
     digitalWrite(MotorRight1,LOW); 
     digitalWrite(MotorRight2,LOW); 
     digitalWrite(MotorLeft1,LOW); 
     digitalWrite(MotorLeft2,LOW); 
 
} 
void back() //後退 
{ 
        digitalWrite(MotorRight1,HIGH); 
        digitalWrite(MotorRight2,LOW); 
        digitalWrite(MotorLeft1,HIGH); 
        digitalWrite(MotorLeft2,LOW);; 
 
} 
 
void loop() 
{ 
  char val = Serial.read(); 
  Serial.write(val); 
  if (-1 != val) { 
    if ('W' == val) 
    go(); 
    else if ('A' ==val) 
    left(); 
    else if ('D' == val) 
    right(); 
    else if ('S' == val) 
    back(); 
    else if ('Q' == val) 
      stop(); 
    delay(500); 
    } 
  else 
  { 
    //stop(); 
    delay(500); 
  } 
}   
 
 
*(範例是否要變更為ArduinoIPS?) 
 
燒入之後出現錯誤訊息 
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00 
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00 
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00 
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00 
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00 
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00 
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00 
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00 
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00 
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00 |   
 
 
 
 |