Hey everyone,
I created a System. This System has got Step Motor and Led. I added buttons with Processing on System but I want to use together all Buttons on System. My problem is here. I am pressing button. It is working. Okay! but I pressed other Buttons but not working at the moment. Other buttons are waiting end of process. I added look like “START” and “STOP” Buttons. If I pressed “START” button, I can’t stop processing. I must wait end of the process. I don’t want to wait. I would you like to process at the moment when press Buttons. I need help for this topic. What should I do? I hope so You can help me. I am sharing codes under this topic. Thanks for reading…
ARDUINO CODES>
int dirPin = 2;
int stepPin = 3;
int ledPin = 4;
int incomingByte = 0;
int stepsPerRevolution = 400;
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("Press 7 to ↓50");
Serial.println("Press 6 to ↑50");
Serial.println("Press 5 to GO HOME");
Serial.println("Press 4 to LED OFF");
Serial.println("Press 3 to LED ON");
Serial.println("Press 2 to StepMotor STOP");
Serial.println("Press 1 to StepMotor >");
Serial.println("Press 0 to StepMotor <");
}
void loop() {
if (Serial.available() > 0) {
}
incomingByte = Serial.read();
if(incomingByte == '7'){
digitalWrite(dirPin, LOW);
for (int i = 0; i < 0.5*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(0);
digitalWrite(stepPin, LOW);
delayMicroseconds(0);
Serial.println("↑50");
}
}else if(incomingByte == '6'){
digitalWrite(dirPin, HIGH);
for (int i = 0; i < 0.5*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(0);
digitalWrite(stepPin, LOW);
delayMicroseconds(0);
Serial.println("↑50");
}
}else if(incomingByte == '5'){
digitalWrite(dirPin, LOW);
for (int i = 0; i < 4*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(0);
digitalWrite(stepPin, LOW);
delayMicroseconds(0);
Serial.println("GO HOME");
incomingByte = Serial.read();
}
}else if(incomingByte == '4'){
digitalWrite(ledPin, LOW);
Serial.println("LED OFF");
}
if(incomingByte == '3'){
digitalWrite(ledPin, HIGH);
Serial.println("LED ON");
}
if(incomingByte == '2'){
Serial.end();
Serial.println("StepMotor STOP");
}
if(incomingByte == '1'){
digitalWrite(dirPin, HIGH);
for (int i = 0; i < 1*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(0);
digitalWrite(stepPin, LOW);
delayMicroseconds(0);
Serial.println("StepMotor >");
}
}else if(incomingByte == '0'){
digitalWrite(dirPin, LOW);
for (int i = 0; i < 1*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(0);
digitalWrite(stepPin, LOW);
delayMicroseconds(0);
Serial.println("StepMotor <");
}
}
}