/*
Dette er en skabililon til Stepper opgave 1
*/
// pinOut on the stepper driver A4988
int Dir_pin = 13; // dir pin
int Step_pin = 12; // step pin
// the Ms pins controlled the stepper motor microstep resolution.
// See https://www.pololu.com/product/1182
int Ms1_pin = 2;
int Ms2_pin = 3;
int Ms3_pin = 4;
// sensor input
// Here you could put a potentiometer on to increase the speed.
int sensor_Knob = A2; // analog input pin.
// These are manual control variables
int delay_time = 100;
int vent = 1000;
int antal_omdrejninger = 100;
void setup() {
// initialize digital output pins.
pinMode(Step_pin, OUTPUT);
pinMode(Dir_pin, OUTPUT);
pinMode(Ms1_pin, OUTPUT);
pinMode(Ms2_pin, OUTPUT);
pinMode(Ms3_pin, OUTPUT);
// initialize analog input pins.
pinMode(sensor_Knob, INPUT);
// initialize serial.
Serial.begin(9600);
}
void loop() {
cw_no_step(antal_omdrejninger);
delay(vent);
ccw_no_step(antal_omdrejninger);
delay(vent);
digitalWrite(Ms1_pin, LOW);
digitalWrite(Ms2_pin, LOW);
digitalWrite(Ms3_pin, LOW);
}
// function that steps a no of steps in one deriction
void cw_no_step (int no_step) {
digitalWrite(Dir_pin, HIGH); // Set the direction of the motor to clockwise
for (int i = 0; i <= no_step ; i++) {
digitalWrite(Step_pin, HIGH); // turn the step pin on (HIGH is the voltage level = 5v or 3,3v dipending on arduino)
delay(5); // wait for a specified time to let the mortor move, in mili sek.
digitalWrite(Step_pin, LOW); // turn the step pin off by making the voltage LOW = 0v
delay(5);
}
}
void ccw_no_step (int no_step) {
digitalWrite(Dir_pin, LOW); // Set the direction of the motor to counter clockwise
for (int i = 0; i <= no_step ; i++) {
digitalWrite(Step_pin, HIGH); // turn the step pin on (HIGH is the voltage level = 5v or 3,3v dipending on arduino)
delay(5); // wait for a specified time to let the mortor move
digitalWrite(Step_pin, LOW); // turn the step pin off by making the voltage LOW = 0v
delay(5);
}
}