Hello,
I am trying to make my Arduino UNO output a voltage to a specififed pin when a button is pressed and given certain input voltages, however it is not doing this. The code compiles and I have run a few tests measuring output voltages to narrow down the problem.
What I know so far:
-
The board identifies input voltages and assigns values to the variables "motorID" and "motorDir" correctly.
-
Using digitalWrite(case0test,HIGH) I found that case 0 works and is executed since I do get a voltage output.
-
case 1 from the primary switch-case statement and and the entirety of both of the secondary switch-case statements that depend on (motorIDout) do not run because the both digitalWrite(case0test,HIGH) and digitalWrite(buttonPresstest,HIGH) do not produce any output voltages.
Ideas?
// Other constants
float recerveddec;
const int sethalfwavelength = 1000;
int motorIDout;
int motorDir;
// Connections to A4988
const int motor1dirPin = 2; // Motor 1 direction
const int motor1stepPin = 3; // Motor 1 movement
const int motor2dirPin = 4; // Motor 2 direction
const int motor2stepPin = 5; // Motor 2 movement
const int case0test = 6; // Case 0 testing
const int case1test = 7; // Case 1 testing
const int motorDirtest = 8; //For nested case testing
const int buttonPresstest = 9;
// Connections to User Interface
const int buttonPress = 10; //Pin for manual control
const int motorIDin = 11; // ID pin for motors
const int controlDir = 12; // Rotation direction definition pin
const int emergencystop = 13; // Emergency stop pin
void setup() {
// Designate Output Pins
pinMode(motor1stepPin,OUTPUT);
pinMode(motor1dirPin,OUTPUT);
pinMode(motor2stepPin,OUTPUT);
pinMode(motor2dirPin,OUTPUT);
pinMode(motorDirtest,OUTPUT);
pinMode(buttonPresstest,OUTPUT);
pinMode(case0test,OUTPUT);
pinMode(case1test,OUTPUT);
// Designate Input Pins
pinMode(buttonPress,INPUT_PULLUP);
pinMode(motorIDin,INPUT_PULLUP);
pinMode(controlDir,INPUT_PULLUP);
pinMode(emergencystop,INPUT_PULLUP);
delay(5000);
}
// Stepper Motor Program Begins and Loops
void loop()
{
recData();
ManMoveMotor();
}
void recData()
{
if (digitalRead(motorIDin) == LOW) {
int motorIDout = 1;
}
else {
int motorIDout = 2;
}
if (digitalRead(controlDir) == LOW) {
int motorDir = 0;
digitalWrite(motorDirtest,LOW);
}
else {
int motorDir = 1;
}
}
void ManMoveMotor()
{
switch (motorDir) {
case 0: //Clockwise rotation case
digitalWrite(motor1dirPin,LOW);
digitalWrite(motor2dirPin,LOW);
digitalWrite(case0test,HIGH);
switch (motorIDout) {
case 1: //To control motor 1
while (digitalRead(buttonPress) == LOW) { // If button is being pressed, execute loop
digitalWrite(motor1stepPin,HIGH);
delayMicroseconds(sethalfwavelength);
digitalWrite(motor1stepPin,LOW);
delayMicroseconds(sethalfwavelength);
digitalWrite(buttonPresstest,HIGH);
}
digitalWrite(buttonPresstest,LOW);
break; //Break for case 1 "motor 1 control"
case 2: //To control motor 2
while (digitalRead(buttonPress) == LOW) { // If button is being pressed, execute loop
digitalWrite(motor2stepPin,HIGH);
delayMicroseconds(sethalfwavelength);
digitalWrite(motor2stepPin,LOW);
delayMicroseconds(sethalfwavelength);
digitalWrite(buttonPresstest,HIGH);
}
digitalWrite(buttonPresstest,LOW);
break; //Break for case 2 "motor 2 control"
}
delay(1);
break; //Break for case 0 "Clockwise rotation"
case 1: //Counter-Clockwise rotation case
digitalWrite(motor1dirPin,LOW);
digitalWrite(motor2dirPin,LOW);
digitalWrite(case1test,HIGH);
switch (motorIDout) {
case 1: //To control motor 1
while (digitalRead(buttonPress) == LOW) { // If button is being pressed, execute loop
digitalWrite(motor1stepPin,HIGH);
delayMicroseconds(sethalfwavelength);
digitalWrite(motor1stepPin,LOW);
delayMicroseconds(sethalfwavelength);
digitalWrite(buttonPresstest,HIGH);
}
digitalWrite(buttonPresstest,LOW);
break; //Break for case 1 "motor 1 control"
case 2: //To control motor 2
while (digitalRead(buttonPress) == LOW) { // If button is being pressed, execute loop
digitalWrite(motor2stepPin,HIGH);
delayMicroseconds(sethalfwavelength);
digitalWrite(motor2stepPin,LOW);
delayMicroseconds(sethalfwavelength);
digitalWrite(buttonPresstest,HIGH);
}
digitalWrite(buttonPresstest,LOW);
break; //Break for case 2 "motor 2 control"
}
delay(1);
break; //Break for case 1 "Counter-Clockwise rotation"
}
delay(1);
digitalWrite(buttonPresstest,LOW);
digitalWrite(case0test,LOW);
digitalWrite(case1test,LOW);
}