Hello friends,
I’m very new to arduino, and cannot find a solution for my problem. I have made a turntable with Leonardo for photography, when I push a button to start loop, it turns 90 degrees - stop - wait for 1 second -send a keystroke to pc, and repeat this 4 times for full 360 degrees and finish, but when I push the start button again, it doesn’t start and I have to reset arduino each time. Please can you give me some advice to solve this problem? Sorry for my bad English.
Here is my sketch
#include <Keyboard.h>
int pinButton = 8;
int smDirectionPin = 2; //Direction pin
int smStepPin = 3; //Stepper pin
void setup(){
const byte buttonPin = 8;
pinMode(buttonPin, INPUT_PULLUP);
while (digitalRead(buttonPin) == HIGH)
pinMode(smDirectionPin, OUTPUT);
pinMode(smStepPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
digitalWrite(smDirectionPin, HIGH); //Writes the direction to the EasyDriver DIR pin. (HIGH is clockwise).
/Slowly turns the motor 1600 steps/
for (int x = 0; x < 400; x++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(1200);
digitalWrite(smStepPin, LOW);
delayMicroseconds(1200);
}
delay(600);
Keyboard.begin();
Keyboard.write(‘a’);
Keyboard.end();
delay(600);
digitalWrite(smDirectionPin, HIGH); //Writes the direction to the EasyDriver DIR pin. (HIGH is clockwise).
/Slowly turns the motor 1600 steps/
for (int x = 0; x < 400; x++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(1200);
digitalWrite(smStepPin, LOW);
delayMicroseconds(1200);
}
delay(600);
Keyboard.begin();
Keyboard.write(‘a’);
Keyboard.end();
delay(600);
digitalWrite(smDirectionPin, HIGH); //Writes the direction to the EasyDriver DIR pin. (HIGH is clockwise).
/Slowly turns the motor 1600 steps/
for (int x = 0; x < 400; x++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(1200);
digitalWrite(smStepPin, LOW);
delayMicroseconds(1200);
}
delay(600); //
Keyboard.begin();
Keyboard.write(‘a’);
Keyboard.end();
delay(600);
digitalWrite(smDirectionPin, HIGH); //Writes the direction to the EasyDriver DIR pin. (HIGH is clockwise).
/Slowly turns the motor 1600 steps/
for (int x = 0; x < 400; x++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(1200);
digitalWrite(smStepPin, LOW);
delayMicroseconds(1200);
}
delay(600); //
Keyboard.begin();
Keyboard.write(‘a’);
Keyboard.end();
delay(600);
while(1) {
}
}