I am getting the error stated in the title. I have tried two different ways of writing the code where I assign the value to the defined int motorDir and still continue to get this error. I followed the same syntax as the website's example for the first instance and a different method of my own in instance 2 and I get the same error for each instance.
The first instance is where the ints for motorDir and motorIDout are defined in "ManMotorMove();" and is currently uncommented. The preferable method would be to define them in "recData();" (And currently commented out) because in the final code set there will be a serial read and I would like to have a section dedicated entirely to reading incoming data and then setting the appropriate voltages to the output pins prior to the rest of the code running. Currently the numerical control that is moved via the serial is commented out/not included in this code set as it is not relevant to the current error so please disregard those parts of the code. Again, either way gives me the same error.
Code:
// Other constants
const byte numChars = 32;
char receivedChars[numChars]; // an array to store the received data
boolean userinput = false;
int dataNumber = 0; // new for this version
float recerveddec;
const int maxstepsize = 32700;
const int minstepsize = 1;
const int sethalfwavelength = 1000; // Set half wavelength to determine speed. Range of available speeds without abnormal vibrations: [1000,3000]. In units of (micro-secnds [10^-6])
// Connections to A4988
const int motor1dirPin = 2; // Motor 1 direction
const int motor1stepPin = 3; // Motor 1 movement
const int motor2dirPin = 4; // Motor 2 direction
const int motor2stepPin = 5; // Motor 2 movement
// Connections to User Interface
const int buttonPress = 10; //Pin for manual control
const int motorIDin = 11; // ID pin for motors
const int controlDir = 12; // Rotation direction definition pin
const int emergencystop = 13; // Emergency stop pin
// const int motorsetrpm = A0; // Set RPM for Pk266-01A and Pk266-01B [RPM/Hz range: 0 to 4500/750] Recomends ~150 RPM or 25 Hz
void setup() {
// Designate Output Pins
pinMode(motor1stepPin,OUTPUT);
pinMode(motor1dirPin,OUTPUT);
pinMode(motor2stepPin,OUTPUT);
pinMode(motor2dirPin,OUTPUT);
// Designate Input Pins
pinMode(buttonPress,INPUT_PULLUP);
pinMode(motorIDin,INPUT_PULLUP);
pinMode(controlDir,INPUT_PULLUP);
pinMode(emergencystop,INPUT_PULLUP);
{
// Initialize serial and wait for port to open:
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
delay(5000);
}
// Stepper Motor Program Begins and Loops
void loop()
{
recData();
displayData();
//NumMoveMotor();
ManMoveMotor();
}
void recData()
{
static byte ndx = 0;
char endMarker = '\n';
char c;
if (Serial.available() > 0) // If there is a serial available, read it
{
// read the incoming byte:
c = Serial.read();
if (c != endMarker)
{
receivedChars[ndx] = c;
ndx++;
if (ndx >= numChars)
{
ndx = numChars - 1;
}
}
else
{
receivedChars[ndx] = '\0'; // terminate the string
Serial.println(receivedChars);
ndx = 0;
userinput = true;
}
}
/*
if (digitalRead(motorIDin) == LOW) {
int motorIDout = 1;
}
else {
int motorIDout = 2;
}
if (digitalRead(controlDir) == LOW) {
int motorDir = 0;
}
else {
int motorDir = 1;
}
*/
}
void displayData()
{
if (userinput == true)
{
recerveddec = atoi(receivedChars);
}
}
// Stepper Motor Program Begins and Loops
void loop()
{
ManMoveMotor();
}
void ManMoveMotor() {
if (digitalRead(motorIDin) == LOW) {
int motorIDout = 1;
}
else {
int motorIDout = 2;
}
if (digitalRead(controlDir) == LOW) {
int motorDir = 0;
}
else {
int motorDir = 1;
}
switch (motorDir) {
case 0: //Clockwise rotation case
digitalWrite(motor1dirPin,LOW);
digitalWrite(motor2dirPin,LOW);
switch (motorIDout) {
case 1: //To control motor 1
while (digitalRead(buttonPress) == LOW) { // If button is being pressed, execute loop
digitalWrite(motor1stepPin,HIGH);
delayMicroseconds(sethalfwavelength);
digitalWrite(motor1stepPin,LOW);
delayMicroseconds(sethalfwavelength);
}
break; //Break for case 1 "motor 1 control"
case 2: //To control motor 2
while (digitalRead(buttonPress) == LOW) { // If button is being pressed, execute loop
digitalWrite(motor1stepPin,HIGH);
delayMicroseconds(sethalfwavelength);
digitalWrite(motor1stepPin,LOW);
delayMicroseconds(sethalfwavelength);
}
break; //Break for case 2 "motor 2 control"
}
delay(1);
break; //Break for case 0 "Clockwise rotation"
case 1: //Counter-Clockwise rotation case
digitalWrite(motor1dirPin,LOW);
digitalWrite(motor2dirPin,LOW);
switch (motorIDout) {
case 1: //To control motor 1
while (digitalRead(buttonPress) == LOW) { // If button is being pressed, execute loop
digitalWrite(motor1stepPin,HIGH);
delayMicroseconds(sethalfwavelength);
digitalWrite(motor1stepPin,LOW);
delayMicroseconds(sethalfwavelength);
}
break; //Break for case 1 "motor 1 control"
case 2: //To control motor 2
while (digitalRead(buttonPress) == LOW) { // If button is being pressed, execute loop
digitalWrite(motor1stepPin,HIGH);
delayMicroseconds(sethalfwavelength);
digitalWrite(motor1stepPin,LOW);
delayMicroseconds(sethalfwavelength);
}
break; //Break for case 2 "motor 2 control"
}
delay(1);
break; //Break for case 1 "Counter-Clockwise rotation"
}
delay(1);
}