Question: Arduino ADK The following code asks the user to enter one of the cases in the serial monitor to move a stepper motor. The cases
Arduino ADK
The following code asks the user to enter one of the cases in the serial monitor to move a stepper motor. The cases are a (Counter Clock Continuously), b (Counter Clockwise Continuously), c: (Counter Clock), d: (Counter Clockwise) and f: (Stop). The problem is that the stepper motor does not do a counter clockwise and does not take any cases, only case a.
#include
void setup() { Serial.begin(9600); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); Serial.begin(9600); }
void loop () { if (Serial.available()>0) { char commandChar = Serial.read(); switch (commandChar){
case 'a':{ //CCC Serial.print(" Enter turns:"); int steps = Serial.parseInt(); int Steps2Take = stepsPerRevolution*steps; myStepper.setSpeed(90); myStepper.step(Steps2Take);} break; case 'b':{ //CCW Serial.print(" Enter turns:"); int steps = Serial.parseInt(); int Steps2Take = - stepsPerRevolution * steps; myStepper.setSpeed(90); myStepper.step(Steps2Take);} break; case 'c':{ //CSC myStepper.step(stepsPerRevolution);} break;
case 'd':{ //CSW myStepper.step(-stepsPerRevolution);} break;
case 'f':{ //STOP myStepper.setSpeed(0);} break;
default:{ Serial.println("Invalid Command");} }}}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
