ZOETROPE Modification

const int controlPin1 = 2;
const int controlPin2 = 3;
const int enablePin = 9;
const int directionSwitchPin = 4;
const int onOffSwitchStateSwitchPin = 5;
const int potPin = A0;
int onOffSwitchState = 0;
int previousOnOffSwitchState = 0;
int directionSwitchState = 0;
int previousDirectionSwitchState = 0;
int motorEnabled = 0;
int motorSpeed = 0;
int motorDirection = 1;
void setup(){

    pinMode(directionSwitchPin, INPUT);
    pinMode(onOffSwitchStateSwitchPin, INPUT);
    pinMode(controlPin1, OUTPUT);
    pinMode(controlPin2, OUTPUT);
    pinMode(enablePin, OUTPUT);
    digitalWrite(enablePin, LOW);

}//Fin de la función setup.
void loop(){

    onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
    delay(1);
    directionSwitchState = digitalRead(directionSwitchPin);
    motorSpeed = analogRead(potPin)/4;
    if (onOffSwitchState != previousOnOffSwitchState) {
        if (onOffSwitchState == HIGH) {
            motorEnabled = !motorEnabled;
        }
    }
    if (directionSwitchState != previousDirectionSwitchState) {
        if (directionSwitchState == HIGH) {
            motorDirection = !motorDirection;
        }
    }
    if (motorDirection == 1) {
        digitalWrite(controlPin1, HIGH);
        digitalWrite(controlPin2, LOW);
    }
    else {
        digitalWrite(controlPin1, LOW);
        digitalWrite(controlPin2, HIGH);
    }
    if (motorEnabled == 1) {
        analogWrite(enablePin, motorSpeed);
    }
    else {
        analogWrite(enablePin, 0);
    }
    previousDirectionSwitchState = directionSwitchState;
    previousOnOffSwitchState = onOffSwitchState;


}//Fin de la función loop.

I have this code. I need that when I press the Switch chage the state of the motor. For exaple, now if I keep press the switch with pin 4, the motor change the direction (right to left) or when I keep press the switch with pin 5, the motor is enable.

I need that when I press the switch, the motor state change without I have to keep press... Can you help me?

For exaple, now if I keep press the switch with pin 4, the motor change the direction (right to left) or when I keep press the switch with pin 5, the motor is enable.

I need that when I press the switch, the motor state change without I have to keep press

If your switches are wired correctly (you've not said that you have wired them correctly, so I have to assume that you haven't), the code should do just what you say you want.

You gave the pins names. Use the names when describing the behavior you want.

const int directionSwitchPin = 4;
const int onOffSwitchStateSwitchPin = 5;

"directionSwitchPin" and "onOffSwitchStateSwitchPin" may to change when I'll press it and not when I'll keep it press.

You are already dealing with state change. So, either the switches are not wired correctly, or the things that happen when the switch states change are not what you want.

    onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
    if (onOffSwitchState != previousOnOffSwitchState)
    {
        Serial.println("The on/off switch changed state...");
        if (onOffSwitchState == HIGH)
        {
            Serial.println("to pressed...");
            motorEnabled = !motorEnabled;
        }
    }

Do you see the appropriate messages in the Serial Monitor when you press and release the switch? If not, there is a wiring problem. If so, there is a logic problem.

We need to know which problem you are trying to solve.

PaulS: You are already dealing with state change. So, either the switches are not wired correctly, or the things that happen when the switch states change are not what you want.

    onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
    if (onOffSwitchState != previousOnOffSwitchState)
    {
        Serial.println("The on/off switch changed state...");
        if (onOffSwitchState == HIGH)
        {
            Serial.println("to pressed...");
            motorEnabled = !motorEnabled;
        }
    }

Do you see the appropriate messages in the Serial Monitor when you press and release the switch? If not, there is a wiring problem. If so, there is a logic problem.

We need to know which problem you are trying to solve.

Can yopu add this part of the program on the original program? Please, help me... I need solve this after Monday,14 . Thanks so much...