I am a NOOB. I admit to a huge lack of understanding of programming. I just need my machine to work.
I cannot wrap my head around getting independent speed control of 2 steppers since it seems that controlling the speed is dependent upon adjusting the length of delay between sending pulses to the motors, however sketches only contain one Loop and any delay in that loop has a global effect.
Here is my code so far
// My sketch to control 1.8 degree stepper motors operating the Gizmoto V3 Braiding Machine
// One 10k Pot speed-controls 2 braiding steppers,
// Second Pot speed-controls 3rd stepper which operates the take-up capstan
// Rev 1.0 March 10 2021
// Defines pins numbers
const int braidStepPin = 3;
const int braidDirPin = 2;
const int capstanStepPin = 5;
const int capstanDirPin = 4;
//Define variables here
int braidDelay; // Controls the speed of the braiding drive according to braidSpeed function
int capstanDelay; // Controls the speed of the capstan drive according to capstanSpeed function
void setup() {
// Sets the pins as Outputs
pinMode(braidStepPin,OUTPUT);
pinMode(braidDirPin,OUTPUT);
pinMode(capstanStepPin,OUTPUT);
pinMode(capstanDirPin,OUTPUT);
digitalWrite(braidDirPin,HIGH); // Sets the braid motors' direction
digitalWrite(capstanDirPin,HIGH); // Sets the capstan motor's direction
}
void loop() {
digitalWrite(braidStepPin, HIGH); // Sends the braid motors one pulse
digitalWrite(braidStepPin, LOW);
delayMicroseconds(braidSpeed);
digitalWrite(capstanStepPin, HIGH); //Sends the capstan motor one pulse
digitalWrite(capstanStepPin, LOW);
delayMicroseconds(capstanSpeed);
}
// Function for reading the Braiding Potentiometer
int braidSpeed() {
int braidDelay = analogRead(A0); // Reads the potentiometer
int newBraidDelay = map(braidDelay, 0, 1020, 200, 700); // Converts the read values of the potentiometer from 0 to 1023 into desired delay values
return newBraidDelay;
}
// Function for reading the Capstan Potentiometer
int capstanSpeed() {
int capstanDelay = analogRead(A1); // Reads the potentiometer
int newCapstanDelay = map(capstanDelay, 0, 1020, 200, 700); // Converts the read values of the potentiometer from 0 to 1023 into desired delay values
return newCapstanDelay;
}
step braid ... pause ... step capstan ... pause
... do you see a problem with that? .... the code needs to belook at time ... if needed, step braid ... if needed, step capstan
.... or this ...decrement braid counter ... if zero, reset braid counter and step braid ... decrement capstan counter ... if zero, reset capstan counter and step capstan
count_value
... remove all the code that deals with the button ... keep the delay just for testing ... you'll haveincrement count_value ... print count_value ... delay 100