Notifications
Clear all

Library syntax

8 Posts
2 Users
1 Likes
102 Views
barrie
(@barrie)
Trusted Member
Joined: 3 months ago
Posts: 86
Topic starter  

How do I use a library function such as: 

runSpeed()

boolean AccelStepper::runSpeed (   )

1) runSpeed() ?

2) bool = runSpeed() ?

3) The library tab also shows it with two colons as above.

Are the colons required syntax when using runSpeed() ?

Can't get the above to format properly. Hope it makes sense.

This topic was modified 2 months ago 2 times by barrie

   
Quote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2112
 
Posted by: @barrie

How do I use a library function such as: 

runSpeed()

 

First you create the object as in ...

AccelStepper myStppr(1,sStep,sDir); // Create the stepper

and then you invoke it by using the method name after specifying the object you wish to operate and then the method name and any parameters required. In this case ...

myStppr.runSpeed();

 

I was kidnapped by mimes.
They did unspeakable things to me.


   
sj_h1 reacted
ReplyQuote
barrie
(@barrie)
Trusted Member
Joined: 3 months ago
Posts: 86
Topic starter  

Thank you.

I have the stepper already defined but I have to declare runSpeed() How do I do that?

AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
 
Is this the declaration? AccelStepper myStppr(1,sStep,sDir); // Create the stepper
If so what are the parameters (1,sStep,sDir)
my guess is 1 = stepper 1, sStep = num of steps for one rotation and sDir = Direction.
This post was modified 2 months ago 2 times by barrie

   
ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2112
 

@barrie 

I suggest that you read the documentation to see what parameters are required for your particular setup.

i am using an A4988 stepper driver and so the constructor I'm using here is specifying that I'm using a driver (which is what the value 1 stands for) and the pin with name sStep is connected to the A4988 drivers "step" pin and the sDir is the name of the pin which is connected to the A4988's "direction" pin.

If you already have the stepper defined (correctly), then you invoke any of its methods by using the name of the stepper object followed by a dot followed by the method name and include any required parameters.

for instance, if you've called your stepper "rover" ...

rover.runSpeed();

rover.setAcceleration(100);

rover.moveTo(1000);

if (rover.distanceToGo()==0) then ... etc ...

 

 

I was kidnapped by mimes.
They did unspeakable things to me.


   
ReplyQuote
barrie
(@barrie)
Trusted Member
Joined: 3 months ago
Posts: 86
Topic starter  

Many thanks. I read the documentation a few times. Since it was my first attempt to use a library function from scratch I needed help to fully understand it. Thanks very much for your clarification and examples.


   
ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2112
 

@barrie 

OK, one more suggestion. If you click the "Reply" at the bottom of a post, it will start a new post for you and start it off with @ plus the handle of the person who wrote the text. That will cause an email to be sent to that person telling them that somebody has responded to that post.

If you just start a new post to reply (as you're doing), then the person you're trying to address is not informed of your reply and so won't know that you answered them until they next randomly check for new postings (and maybe not then if they're not concentrating on the thread).

I was kidnapped by mimes.
They did unspeakable things to me.


   
ReplyQuote
barrie
(@barrie)
Trusted Member
Joined: 3 months ago
Posts: 86
Topic starter  

@will Very good point. Thank you.


   
ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2112
 

@barrie 

There you go 🙂

I was kidnapped by mimes.
They did unspeakable things to me.


   
ReplyQuote