10-03-2016, 12:39 AM
Uspeo sam da iskombinujem kod da pali na taser.
Sad kad pritisnem taster odradi jednom i stane dok ne pritisnem opet.
int inA1 = 2; // input 1 of the stepper
int inA2 = 3; // input 2 of the stepper
int inB1 = 6; // input 3 of the stepper
int inB2 = 9; // input 4 of the stepper
int stepDelay = 3; // Delay between steps in milliseconds
int buttonPin;
void setup() {
buttonPin = 12 ; //whatever pin your button is plugged into
pinMode(buttonPin, INPUT_PULLUP);
pinMode(inA1, OUTPUT);
pinMode(inA2, OUTPUT);
pinMode(inB1, OUTPUT);
pinMode(inB2, OUTPUT);
}
void step1() {
digitalWrite(inA1, LOW);
digitalWrite(inA2, HIGH);
digitalWrite(inB1, HIGH);
digitalWrite(inB2, LOW);
delay(stepDelay);
}
void step2() {
digitalWrite(inA1, LOW);
digitalWrite(inA2, HIGH);
digitalWrite(inB1, LOW);
digitalWrite(inB2, HIGH);
delay(stepDelay);
}
void step3() {
digitalWrite(inA1, HIGH);
digitalWrite(inA2, LOW);
digitalWrite(inB1, LOW);
digitalWrite(inB2, HIGH);
delay(stepDelay);
}
void step4() {
digitalWrite(inA1, HIGH);
digitalWrite(inA2, LOW);
digitalWrite(inB1, HIGH);
digitalWrite(inB2, LOW);
delay(stepDelay);
}
void stopMotor() {
digitalWrite(inA1, LOW);
digitalWrite(inA2, LOW);
digitalWrite(inB1, LOW);
digitalWrite(inB2, LOW);
}
void loop ()
{
if(digitalRead(buttonPin) == LOW)
{
for (int i=0; i<=11; i++){
step1();
step2();
step3();
step4();
step1();
step2();
step3();
step4();
}
stopMotor ();
delay (3000) ;
}
}
Sad kad pritisnem taster odradi jednom i stane dok ne pritisnem opet.

int inA1 = 2; // input 1 of the stepper
int inA2 = 3; // input 2 of the stepper
int inB1 = 6; // input 3 of the stepper
int inB2 = 9; // input 4 of the stepper
int stepDelay = 3; // Delay between steps in milliseconds
int buttonPin;
void setup() {
buttonPin = 12 ; //whatever pin your button is plugged into
pinMode(buttonPin, INPUT_PULLUP);
pinMode(inA1, OUTPUT);
pinMode(inA2, OUTPUT);
pinMode(inB1, OUTPUT);
pinMode(inB2, OUTPUT);
}
void step1() {
digitalWrite(inA1, LOW);
digitalWrite(inA2, HIGH);
digitalWrite(inB1, HIGH);
digitalWrite(inB2, LOW);
delay(stepDelay);
}
void step2() {
digitalWrite(inA1, LOW);
digitalWrite(inA2, HIGH);
digitalWrite(inB1, LOW);
digitalWrite(inB2, HIGH);
delay(stepDelay);
}
void step3() {
digitalWrite(inA1, HIGH);
digitalWrite(inA2, LOW);
digitalWrite(inB1, LOW);
digitalWrite(inB2, HIGH);
delay(stepDelay);
}
void step4() {
digitalWrite(inA1, HIGH);
digitalWrite(inA2, LOW);
digitalWrite(inB1, HIGH);
digitalWrite(inB2, LOW);
delay(stepDelay);
}
void stopMotor() {
digitalWrite(inA1, LOW);
digitalWrite(inA2, LOW);
digitalWrite(inB1, LOW);
digitalWrite(inB2, LOW);
}
void loop ()
{
if(digitalRead(buttonPin) == LOW)
{
for (int i=0; i<=11; i++){
step1();
step2();
step3();
step4();
step1();
step2();
step3();
step4();
}
stopMotor ();
delay (3000) ;
}
}