2023-06-27 11:14:02 +02:00
const int stepPin = 14 ;
2023-06-20 15:41:52 +02:00
2023-06-27 11:14:02 +02:00
const int dirPin = 12 ;
2023-06-20 15:41:52 +02:00
2023-06-27 11:14:02 +02:00
int customDelay , customDelayMapped ; // Defines variables
2023-06-20 15:41:52 +02:00
2023-06-27 11:14:02 +02:00
void setup ( ) {
// Sets the two pins as Outputs
Serial . begin ( 115200 ) ;
2023-06-20 15:41:52 +02:00
2023-06-27 11:14:02 +02:00
pinMode ( stepPin , OUTPUT ) ;
pinMode ( dirPin , OUTPUT ) ;
digitalWrite ( dirPin , HIGH ) ; //Enables the motor to move in a particular direction
2023-06-20 15:41:52 +02:00
2023-06-26 15:10:20 +02:00
}
2023-06-27 11:14:02 +02:00
void loop ( ) {
customDelayMapped = speedUp ( ) ; // Gets custom delay values from the custom speedUp function
// Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
digitalWrite ( stepPin , HIGH ) ;
delayMicroseconds ( customDelayMapped ) ;
digitalWrite ( stepPin , LOW ) ;
delayMicroseconds ( customDelayMapped ) ;
Serial . println ( customDelayMapped ) ;
2023-06-26 15:04:13 +02:00
}
2023-06-27 11:14:02 +02:00
// Function for reading the Potentiometer
int speedUp ( ) {
int customDelay = analogRead ( 6 ) ; // Reads the potentiometer
int newCustom = map ( customDelay , 0 , 8191 , 300 , 3000 ) ; // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
return newCustom ;
2023-06-26 15:04:13 +02:00
}