Untuk control stepper motor ni kene ade
- Stepper motor (mane2 tak kisah tapi yang aku jual memang bole masuk)
- Arduino board (Mega, UNO, Mini @ Nano.. yang lain maybe boleh)
- Easy Driver (aku ade jual gak)
- Breadboard/ Circuit board pon boleh
- Jumper wire
- Tactile switch, yang switch aku tekan tu la ( ade jual jugak, tgk store aku)
Dan ini codenya...
//Basic code by MSIDRIS for Manual control stepper motor
// Using Easy driver and Arduino uno..
int delays;
const int ManPosY = 4; //Manual input from switch to control + direction
const int ManNegY = 5; //Manual input from switch to control - direction
const int DirY = 8;
const int LocY = 9;
float buttonPushCounterPosy,buttonPushCounterNegy = 0;// counter for the number of button presses
int buttonStatex = 0;
int buttonStatePosy, buttonStateNegy,buttonStatePosx = 0; // current state of the button
int lastButtonStatePosy,lastButtonStateNegy = 0;
void setup() {
Serial.begin(9600);
pinMode(ManPosY, INPUT); //override y +ve
pinMode(ManNegY, INPUT); //override y -ve
pinMode(DirY, OUTPUT);
pinMode(LocY, OUTPUT);
digitalWrite(DirY, LOW);
digitalWrite(LocY, LOW);
}
void loop() {
buttonStatePosy = digitalRead(ManPosY);
buttonStateNegy = digitalRead(ManNegY);
if ((digitalRead(ManPosY)==HIGH)){
buttonPushCounterPosy++;
delay(200);
while(round(buttonPushCounterPosy/2-round(buttonPushCounterPosy/2))!=0){
if (digitalRead(ManPosY)==HIGH){buttonPushCounterPosy++;}
delays=100;
digitalWrite(DirY,LOW) ;
digitalWrite(LocY, HIGH);delayMicroseconds(delays);
digitalWrite(LocY, LOW);delayMicroseconds(delays);
}
delay(200);}
if ((digitalRead(ManNegY)==HIGH)){
buttonPushCounterNegy++;
delay(200);
while(round(buttonPushCounterNegy/2-round(buttonPushCounterNegy/2))!=0){
if (digitalRead(ManNegY)==HIGH){buttonPushCounterNegy++;}
delays=100;
digitalWrite(DirY,HIGH) ;
digitalWrite(LocY, HIGH);delayMicroseconds(delays);
digitalWrite(LocY, LOW);delayMicroseconds(delays);
}
delay(200);}
}
tekan sekali untuk jalan dan tekan sekali lagi untuk stop...
No comments:
Post a Comment