Using array to control motor positions

Hello,

I am running across an issue when I have tried implementing a menu to select which "recipe"(which is an array) to make, and then using that to control stepper motor positons, this uses Accelstepper library but I don't believe this will affect this issue.
The error is get is regarding setting moveToNext = recipeBeingMade[any number to get the steps in the recipe array] where it says cannot have type of 'int[int]'.
Apologies if I'm dumb and attempting to do something impossible, only just started coding.. Any ideas on how I could make this work, where I'm going wrong, or better ways of accomplishing this?
My code is long, but this is the relevant section to this question:

//Declaring
int recipeToBeMade;
int recipeBeingMade;
int recipeOne[] = { -1000, -4000, -10000, -300 };
int recipeTwo[] = { -3000, -10000, - 5000, -300 };
const byte recipeBeingMadeSize = sizeof(recipeBeingMade) / sizeof(recipeBeingMade[0]);

void selectRecipe()
{
  int recipeInput;
  do
  {
    Serial.println("Enter which recipe to make");
    recipeInput = Serial.read();
    Serial.println(recipeInput);
  }
  while (!Serial.available());
  {
    Serial.println("No serial data available");
    //Wait
  }
  
  recipeToBeMade = recipeInput - '0';
  switch (recipeInput)
    {
      case 1:
      recipeBeingMade = recipeOne[];
      break;
    } 
}

void executeRecipe()
{
    if (conveyor.currentPosition() == 0)
    {
      if (recipeBeingMadeSize >= 1)
      {
        moveToNext = recipeBeingMade[0];
      }
    }
    if (conveyor.currentPosition() == recipeBeingMade[0])
    {
      if (recipeBeingMadeSize >= 2)
      {
        moveToNext = recipeBeingMade[1];
      }
    }
}

Actually, what is relevant is "when did the problem first occur and what was the last change you made that showed the problem"?
Also relevant is are you using the serial monitor to display the steps and values in you code as it is executed?
Paul

int recipeBeingMade;

recipeBeingMade is a scalar (single value) int but here

moveToNext = recipeBeingMade[1];

you use it as if it were an array

No wonder the compiler reports an error

The problem occured as soon as I started trying to use the array "through" another variable. I'm using the serial monitor to display what it's set to when it sets it, but not even getting there due to the compile error.

And I know I'm using it as if it were an array-I guess my question is ultimately how do I accomplish having a single variable being equal to different arrays? I can't have recipeBeingMade be an array as the sizes are different between the recipe's, and I can't define a size larger than any recipe due to the extra 0's then being where the stepper motor goes, which I don't want.

Time to study structures and pointers.
Paul

What you could do is to declare a two dimensional array with one row per recipe and one column per conveyor position. Put a dummy but recognisable value in the unwanted positions at the end of the rows and test for them when reading data from the array and don't use them. This will waste some memory but is an easy solution

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.