|
請問我的程式碼都一樣#include <Stepper.h>
//int incomingByte = 0;
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 2, 3, 4, 5);
char val;
int pos=0;
int x;
void setup() {
// myStepper.setSpeed(60);
Serial.begin(9600); //Start serial connection, 9600 baud
}
void loop() {
if(Serial.available() > 0){
Serial.println("Serial.available");
Serial.println(val);
val = Serial.read();
}
if( val == '1' ) //if diference is greater than 2 steps.
{
Serial.println("turn right");
myStepper.step(1); // move one step to the left.
delay(50);
//pos++;
Serial.println(x);
}
else if( val == '0')
{
Serial.println("turn left");
myStepper.step(-1); // move one step to the right.
delay(50);
//pos--;
Serial.println(x);
}
else if( val == '2')
{
Serial.println("stop");
myStepper.step(0); // move one step to stop
delay(50);
//pos--;
Serial.println(x);
}
// Serial.println(pos); //for debuging...
// Serial.println(val);
// delay(100);
}
原本輸入0或是1會正反轉 現在變成輸入0或是1會左右一直極小幅度的轉
請問是不是因為上次接電源供應器結果顯示短路的原因呢..我的版子是LEONARDO
上次也發生過這樣的問題 結果是換一塊版子才成功 (也是用一樣的程式碼) |
|