#include <TM1637Display.h>
int data= 5;
int clock = 4;
TM1637Display display(clock, data);
const int stepsPerRevolution = 200; // Steps per full revolution (1.8° per step)
const float stepsPerDegree = stepsPerRevolution / 360.0; // Steps needed for 1 degree
// Motor 1 pins
const int stepPin = 2; // Step pin for the motor
const int dirPin = 3; // Direction pin for the motor
const int pot = A0;
int delay_time =0;
int pb_left= 13;
int pb_right =12;
int state_left=HIGH;
int state_right=HIGH;
void setup() {
// put your setup code here, to run once:
pinMode(pb_left, INPUT_PULLUP);
pinMode(pb_right, INPUT_PULLUP);
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
display.setBrightness(0);
}
void loop() {
delay_time= map(analogRead(pot),0,1023,1000,10);
float delay_in_seconds = delay_time/1000000;
float speed = 1/delay_in_seconds;
display.showNumberDec((int)(speed));
state_left = digitalRead(pb_left);
if(state_left==LOW){
digitalWrite(dirPin, LOW);
}
state_right = digitalRead(pb_right);
if(state_right==LOW){
digitalWrite(dirPin, HIGH);
}
//digitalWrite(dirPin, HIGH);
// put your main code here, to run repeatedly:
digitalWrite(stepPin, HIGH);
delayMicroseconds(delay_time);
digitalWrite(stepPin, LOW);
delayMicroseconds(delay_time);
}