| 
 | 
回復 12# 超新手  
 
 
   #include <Stepper.h>  char val;  
int s,count; 
Stepper stepper(200, 13, 12, 11, 10);   
void setup()   
{   
Serial.begin(9600);   
stepper.setSpeed(140);     // 將馬達的速度設定成140RPM 最大  150~160   
}   
void loop()   
{   
  if(s==1) 
  { 
    stepper.step(s); 
    count+=1; 
    if(count>1500){ 
    s=-1; 
    count=0;} 
  } 
  if(s==-1){ 
    stepper.step(s); 
    count+=1; 
    if(count>1500){ 
      s=1; 
      count=0;} 
    } 
if (Serial.available()) { 
val = Serial.read(); 
switch(val){ 
  case 'd': 
  Serial.print(val); 
  count=0; 
  s=1; 
  break; 
  case 'f': 
  Serial.print(val); 
  s=0; 
  break; 
 
 
  } 
} 
}   
 
 
 
 
 
我改好了 
是這樣嗎? 
功能是正確的 |   
 
 
 
 |