Unfortunately the motor does not run although the Serial.println does work.
Was wondering if there is an issue with how I have set up the code.
I am using two motor shields.
The motor shield works when the code stopFlow() function is within the void() loop but does not work when it is within the if statement.
Thanks for your help.
Miguel
Code: Select all
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMStop(0x61);
Adafruit_MotorShield AFMSbottom(0x60);
Adafruit_StepperMotor *myStepper1 = AFMStop.getStepper(100,2);
Adafruit_DCMotor *myMotor1 = AFMSbottom.getMotor(1);
int motorSpeed=0;
int motorOn;
String inData;
String motorStat;
void setup() {
Serial.begin(9600);
Serial.println("Water Pump MotorShield Test");
AFMStop.begin();
AFMSbottom.begin();
}
void loop() {
motorSpeed = Serial.read();
if (motorSpeed =='1'){
goFlow();
Serial.println("Water flowing!");
}
if (motorSpeed =='2'){
stopFlow();
Serial.println("Water not flowing!");
}
}
void goFlow(){
myMotor1->run(FORWARD);
myMotor1->setSpeed(10);
myMotor1->run(RELEASE);
}
void stopFlow(){
myMotor1->run(BACKWARD);
myMotor1->setSpeed(10);
myMotor1->run(RELEASE);
}
void stopPump(){
myMotor1->setSpeed(0);
}