Excuse me for being so late.
Yes, you may be right. There might be a simpler way.
First of all: I have built a machine that is able to paint oil-pictures in neo-impressionistic style by using the "color dot method". The only machine of this kind worldwide.
In addition to this, I am using a "color shaker" which is able to dilute oil color from tubes with turpentine. This is where I am working on here now.
At current time, I am using this code here:
const byte potStep = A1; // the pin where the wiper of the potentiometer is connected to
const byte potSpeedPin = A0; // pot pin for handling speed
const int stepPin = 3; // define pin for step
const int dirPin = 4; // define pin for direction
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
Serial.begin(115200);
Serial.println(F("Ready"));
}
void loop() {
// reading the pot's induced voltage value. 0 means 0V and 1023 means 5V - usually linear in between
int potSample = analogRead(potStep);
// map the value that we read between 0 and 1023 into a new value between 20 and 300
int numberOfSteps = map(potSample, 0, 1500, 10, 70);
// calculate the desired speed, here we do it all in one go
unsigned long customDelay = map(analogRead(potSpeedPin), 0, 1023, 8000, 16300);
// set direction clockwise
digitalWrite(dirPin, HIGH);
for (int x = 0; x < numberOfSteps; x++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelay);
}
delay(300);
// set direction anticlockwise
digitalWrite(dirPin, LOW);
for (int x = 0; x < numberOfSteps; x++) { // loop for 100 steps
digitalWrite(stepPin, HIGH);
delayMicroseconds(customDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(customDelay);
}
delay(300);
}
As you can see, there are two potentiometers. One for the speed and one for the depth.
But now I would like to add an option where I could press a button (Dip-Switch) and then the speed as well as the depth dim down from 10 to 0 in (let's say) 10 seconds.
Maybe one could add some code or ... maybe use a second UNO and then connect two digital potentiometers.
What do you think ?