Hello,
I am in a need of help i have a project that consist of controlling a DC motor speed with a potentiometer and a L298D . I made it only that far, now i'm stuck to how to add a display that shows the speed . I have no idea how to write it's code.Please i really need help.
The code:
// Arduino DC motor speed and direction control
#define button 8
#define pot 0
#define pwm1 9
#define pwm2 10
boolean motor_dir = 0;
int motor_speed;
void setup() {
pinMode(button, INPUT_PULLUP);
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
}
void loop() {
motor_speed = analogRead(pot) / 4;
if(motor_dir)
analogWrite(pwm1, motor_speed);
else
analogWrite(pwm2, motor_speed);
if(!digitalRead(button)){ // If direction button is pressed
while(!digitalRead(button)); // Wait until direction button released
motor_dir = !motor_dir; // Toggle direction variable
if(motor_dir)
digitalWrite(pwm2, 0);
else
digitalWrite(pwm1, 0);
}
}