// create some variables to hold values from your inputsint onOffSwitchState = 0; // current state of the On/Off switchint previousOnOffSwitchState = 0; // previous position of the on/off switchint directionSwitchState = 0; // current state of the direction switchint previousDirectionSwitchState = 0; // previous state of the direction switch

// read the value of the pot and divide by 4 to get // a value that can be used for PWM motorSpeed = analogRead(potPin)/4;

// if the on/off button changed state since the last loop() if(onOffSwitchState != previousOnOffSwitchState){ // change the value of motorEnabled if pressed if(onOffSwitchState == HIGH){ motorEnabled = !motorEnabled; } }

// if the direction button changed state since the last loop() if (directionSwitchState != previousDirectionSwitchState) { // change the value of motorDirection if pressed if (directionSwitchState == HIGH) { motorDirection = !motorDirection; } }

// if the motor is supposed to be on if (motorEnabled == 1) { // PWM the enable pin to vary the speed analogWrite(enablePin, motorSpeed); } else { // if the motor is not supposed to be on //turn the motor off analogWrite(enablePin, 0); } // save the current On/Offswitch state as the previous previousDirectionSwitchState = directionSwitchState; // save the current switch state as the previous previousOnOffSwitchState = onOffSwitchState;}

// create some variables to hold values from your inputsint onOffSwitchState = 0; // current state of the On/Off switchint previousOnOffSwitchState = 0; // previous position of the on/off switchint directionSwitchState = 0; // current state of the direction switchint previousDirectionSwitchState = 0; // previous state of the direction switch

// read the value of the pot and divide by 4 to get // a value that can be used for PWM motorSpeed = analogRead(potPin)/4;

// if the on/off button changed state since the last loop() if(onOffSwitchState != previousOnOffSwitchState){ // change the value of motorEnabled if pressed if(onOffSwitchState == HIGH){ motorEnabled = !motorEnabled; } }

// if the direction button changed state since the last loop() if (directionSwitchState != previousDirectionSwitchState) { // change the value of motorDirection if pressed if (directionSwitchState == HIGH) { motorDirection = !motorDirection; } }

// if the motor is supposed to be on if (motorEnabled == 1) { // PWM the enable pin to vary the speed analogWrite(enablePin, motorSpeed); } else { // if the motor is not supposed to be on //turn the motor off analogWrite(enablePin, 0); } // save the current On/Offswitch state as the previous previousDirectionSwitchState = directionSwitchState; // save the current switch state as the previous previousOnOffSwitchState = onOffSwitchState;}