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 const int stepsPerRevolution = 200; Stepper myStepper(stepsPerRevolution, 3, 4, 5, 6);

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!