#define stepPin 12 //pulse #define dirPin 11 //dir #define enaPin 10 //ena long Steps = 0; //Number of steps long Speed = 0; // milli second char command; //------- void setup() { // put your setup code here, to run once: pinMode(stepPin,OUTPUT);//Pul pinMode(dirPin,OUTPUT);//Dir pinMode(enaPin,OUTPUT); Serial.begin(9600); Serial.println("enter a number between 1 to 10000"); while(Serial.available()==0){} } //------- void loop() { // put your main code here, to run repeatedly: receiveFromSerial(); } //------- void receiveFromSerial(){
if (Serial.available() > 0) { command = Serial.read(); switch (command) { case 'a': Steps=Serial.parseInt(); Speed=Serial.parseInt(); Serial.println("CW."); forward(Steps,Speed); break; case 'b': Steps=Serial.parseInt(); Speed=Serial.parseInt(); Serial.println("CCW."); reverse(Steps,Speed); break; default: // statements break; }
#define stepPin 12 //pulse
#define dirPin 11 //dir
#define enaPin 10 //ena
long Steps = 0; //Number of steps
long Speed = 0; // milli second
char command;
//-------
void setup() {
// put your setup code here, to run once:
pinMode(stepPin,OUTPUT);//Pul
pinMode(dirPin,OUTPUT);//Dir
pinMode(enaPin,OUTPUT);
Serial.begin(9600);
Serial.println("enter a number between 1 to 10000");
while(Serial.available()==0){}
}
//-------
void loop() {
// put your main code here, to run repeatedly:
receiveFromSerial();
}
//-------
void receiveFromSerial(){
if (Serial.available() > 0) {
command = Serial.read();
switch (command) {
case 'a':
Steps=Serial.parseInt();
Speed=Serial.parseInt();
Serial.println("CW.");
forward(Steps,Speed);
break;
case 'b':
Steps=Serial.parseInt();
Speed=Serial.parseInt();
Serial.println("CCW.");
reverse(Steps,Speed);
break;
default:
// statements
break;
}
}
}
void forward (float steps, float dly){
int i;
digitalWrite(enaPin,LOW);
digitalWrite(dirPin,HIGH);
for(i=0;i