int motormode;
int direction;
int stepnum;
float Frequser;
String ans;
int arrfull[8] = { 12, 12, 6, 6, 3, 3, 9, 9 };
int arrhalf[8] = { 8, 8, 4, 4, 2, 2, 1, 1 };
int arrwave[8] = { 8, 12, 4, 6, 2, 3, 1, 9 };
int arraymode[8];
void setup() {
Serial.begin(9600);
Serial.println("Enter values:");
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
/*
//gitimg the values from the user
Serial.println("Enter your motor mode:");
delay(200);
while (Serial.available() == 0) {};
delay(200);
motormode = Serial.readString().toInt();
delay(200);
Serial.print("Motor Mode: ");
Serial.println(motormode);
Serial.println("Enter your motor direction:");
delay(200);
while (Serial.available() == 0) {};
delay(200);
direction = Serial.readString().toInt();
delay(200);
Serial.print("Direction: ");
Serial.println(direction);
Serial.println("Enter your motor steps number:");
delay(200);
while (Serial.available() == 0) {};
delay(200);
stepnum = Serial.readString().toInt();
delay(200);
Serial.print("Steps Number: ");
Serial.println(stepnum);
Serial.println("Enter your motor freq:");
delay(200);
while (Serial.available() == 0) {};
delay(200);
Frequser = Serial.readString().toInt();
delay(200);
Serial.print("Frequency: ");
Serial.println(Frequser);
//gitimg the values from the user
*/
//gitimg the values from the user
Serial.println("Enter your motor mode:");
while(Serial.available()==0){};
delay(3000);
motormode=Serial.parseInt();
Serial.println("Enter your motor direction:");
while(Serial.available()==0){};
delay(3000);
direction=Serial.parseInt();
Serial.println("Enter your motor steps number:");
while(Serial.available()==0){};
delay(3000);
stepnum=Serial.parseInt();
Serial.println("Enter your motor freq:");
while(Serial.available()==0){};
delay(3000);
Frequser=Serial.parseInt();
//gitimg the values from the user
//show the values from user
Serial.print("Motor Mode: ");
Serial.println(motormode);
Serial.print("Direction: ");
Serial.println(direction);
Serial.print("Steps Number: ");
Serial.println(stepnum);
Serial.print("Frequency: ");
Serial.println(Frequser);
//show the values from user
//build the new array
if (motormode == 1) {
for (int i = 0; i < 8; i++) {
if (direction == -1) {
arraymode[i] = arrfull[8 - i];
} else {
arraymode[i] = arrfull[i];
}
}
}
else if (motormode == 2) {
for (int i = 0; i < 8; i++) {
if (direction == -1) {
arraymode[i] = arrhalf[8 - i];
} else {
arraymode[i] = arrhalf[i];
}
}
}
else if (motormode == 3) {
for (int i = 0; i < 8; i++) {
if (direction == -1) {
arraymode[i] = arrwave[8 - i];
} else {
arraymode[i] = arrwave[i];
}
}
}
//show the value in port B
for (int i = 0; i < stepnum; i++) {
for (int j = 0; j < 8; j++) {
int value = arraymode[j];
for (int pin = 8; pin <= 11; pin++) {
digitalWrite(pin, (value & 1) ? HIGH : LOW);
value >>= 1;
}
//delay(Frequser);
delay((1 / Frequser) * 1000);
}
}
}