Hi,
I'm using Big Easy Driver for controlling a stepper motor with a potentiometer for speed of rotation. Also, I'm using buttons for start/stop - reverse and speed up funtions of the motor.
So far so good.
Now, my goal is to have a Display Module 7-Segment 2 Digit LED display, just for using it as a reference for me, to show where the value of speed of the motor is.
Here is my code for controlling the stepper :
#include <Stepper.h>
Stepper stepper(400, 9, 8);
const int buttonPin = 3;
const int buttonPin2 = 4;
const int buttonPin3 = 5;
const int buttonPin4 = 6;
int buttonState = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
const int led1 = 10;
const int led2 = 11;
const int led3 = 12;
const int led4 = 13;
void setup()
{
pinMode(buttonPin, INPUT);//set inputs and outputs.
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop()
{
int buttonState = digitalRead(buttonPin);
int buttonState2 = digitalRead(buttonPin2);
int buttonState3 = digitalRead(buttonPin3);
int buttonState4 = digitalRead(buttonPin4);
int motorStep = 30;
int val = analogRead(A0); // get the sensor value
int motorSpeed = map(val, 0, 1023, 0, 1500);//motor speed range.
if (buttonState2 == HIGH){ // BUTTON 2
motorSpeed *= 2; // double the speed of the motor.
digitalWrite(led2, HIGH);
}
else {
digitalWrite(led2, LOW); // the led for double the speed.
}
if (buttonState4 == HIGH){ // BUTTON 4
motorSpeed *= 4; // x4 the speed of the motor.
digitalWrite(led4, HIGH);
}
else {
digitalWrite(led4, LOW); // the led for x4
}
stepper.setSpeed(motorSpeed); // set the speed of the motor in RPM.
if (buttonState == LOW){ //BUTTON 1
motorStep = 0; // Switch to start/stop the motor
digitalWrite(led1, LOW);
}
else {
digitalWrite(led1, HIGH);
}
if (buttonState3 == HIGH){ // BUTTON 3
motorStep = - motorStep; // Reverse motion.
digitalWrite(led3, HIGH);
}
else {
digitalWrite(led3, LOW); // the led for reverse.
}
stepper.step(motorStep);
}
Here is my connections
The segment display that I have is the following:
https://grobotronics.com/display-module-7-segment-2-digit.html
I can't find online a decent tutorial of what I trying to do.
Again, I'm trying to get a reference value of my "motorSpeed" value, mapped from 0 to 99 (cause of the 2 digits)
I hope my query will be clear for someone reading this post.
Any comment or advice will be appreciated
Thank you,
Jtel