Buying advice wanted

Hello.
I'm wondering if my code that I have in arduino UNO will work with all the arduinos, I'm looking for a more powerful arduino than the UNO but I just want to make sure my code works with the device/devices before purchasing.

Thank you

Here's the code (just in case) :

#include <AccelStepper.h>
#include <SM.h>
const int buttonPin = 14; 

int buttonState = 0; 


SM Controller(Parked);
AccelStepper stepper1(AccelStepper::FULL2WIRE, 2, 3);

void setup()
{ 
  pinMode(buttonPin, INPUT);
  stepper1.setMaxSpeed(10000.0);
  stepper1.setAcceleration(14000.0);
  stepper1.moveTo(64000);
}

void loop(){
  buttonState = digitalRead(buttonPin);
  EXEC(Controller);
  stepper1.run();
}//loop()

State Parked(){//wait for sensor to be activated
    
   
  if(analogRead(A2)>600){
    stepper1.setCurrentPosition(0);
  stepper1.stop(); }
  if (buttonState == LOW) 
  { 
    Controller.Set(SlowH, SlowB);
  }
  else if (analogRead(A2)<600){
    stepper1.moveTo(-70000);}
}//Parked()

State SlowH(){// start moving forward at slow speed
  stepper1.moveTo(27000);
  stepper1.setSpeed(2000);
}//SlowH()

State SlowB(){//check remainng distance while moving
  if(stepper1.distanceToGo() == 0) Controller.Set(FastH, FastB);
}//SlowB()

State FastH(){
  stepper1.moveTo(64000);
  stepper1.setSpeed(4000);
}//FastH()

State FastB(){
 if(stepper1.distanceToGo() == 0) Controller.Set(ReverseC); 
}//FastB

State ReverseH(){
  stepper1.moveTo(0);

}//ReverseH()

State ReverseB(){
  
  if(stepper1.distanceToGo() == 0)
   Controller.Set(ReverseC);
}//ReverseB()


State ReverseC(){
  

if (analogRead(A2)>600)
{
      stepper1.setCurrentPosition(0);
      Controller.Set(SlowH, SlowB);
}
else
{ stepper1.moveTo(-70000);
  stepper1.setSpeed(-8000);
}
}

As written, no your code will not work on other Arduino processors. If you change the definition of:

const int buttonPin = 14;

to:

const int buttonPin = A0;

it has a better chance of working on the Leonardo, Mega, Due class processors, which start the analog pins at different pin numbers (Leonard has A0 at 18, Mega 2560/Due at 54). I am not familiar with the libraries, so I can't say if there are problems on other microprocessors.

The due is the one I'm the most interested in, just don't know if the libraries will work.

PZ2332:
The due is the one I'm the most interested in, just don't know if the libraries will work.

A big help towards checking this is to install the libraries in the Due compatible IDE and then try to verify your sketch with target board type selected.

Thanks, I downloaded it and tried it, I'm getting one error though. "undefined reference to `timer0_millis'". Is this solvable?

PZ2332:
Thanks, I downloaded it and tried it, I'm getting one error though. "undefined reference to `timer0_millis'". Is this solvable?

It (timer0_millis) seems to be part of the millis() function call so probably your code or one of the libraries tries to access the value directly (not sure this is the proper way to do it). Due uses a different method so the thing fails. I would prefer someone more knowledgeable on Due to comment but maybe replacing timer0_millis with millis will work.

EDIT:
Probably a good idea to attach the project and any non standard libraries so code can be reviewed.

The problem is with the SM library and this code

//save som time by reading variable directly
extern volatile unsigned long timer0_millis;

Try commenting out the 'extern volatile' line and replacing the references to timer0_millis with millis() in the same SM.h file.

return timer0_millis - Mark;

would become

return millis() - Mark;

You may need to restart the IDE after making changes but for me the code now compiles though this is no guarantee it will work.

Thanks alot! :sweat_smile: