Motor shield - use variable to pass "FORWARD" or "BACKWARD"

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Coopsta
 
Posts: 3
Joined: Thu Dec 15, 2022 5:45 pm

Motor shield - use variable to pass "FORWARD" or "BACKWARD"

Post by Coopsta »

I have created a variable (dir) based on a joy stick input, that will be "FORWARD", "BACKWARD", or "RELEASE". I can print the variable to the serial monitor, but when I use it like this:
motorR.run(dir);

I get error message:
no matching function for call to 'AF_DCMotor::run(String&)'

Help greatly appreciated!

User avatar
adafruit_support_carter
 
Posts: 29158
Joined: Tue Nov 29, 2016 2:45 pm

Re: Motor shield - use variable to pass "FORWARD" or "BACKWARD"

Post by adafruit_support_carter »

The run method takes a uint8_t (unsigned integer):
https://adafruit.github.io/Adafruit_Mot ... e37d4e518c

You are trying to pass it a string.

User avatar
Coopsta
 
Posts: 3
Joined: Thu Dec 15, 2022 5:45 pm

Re: Motor shield - use variable to pass "FORWARD" or "BACKWARD"

Post by Coopsta »

Thanks for looking.
How can the command "FORWARD" be a uint8_t? Is it possible for these run commands to be a variable?

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor shield - use variable to pass "FORWARD" or "BACKWARD"

Post by adafruit_support_bill »

The commands are defined in the header file like this:

Code: Select all

#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4
You can pass the command as a variable. But the variable needs to be an integer type. Ideally uint8_t.

User avatar
Coopsta
 
Posts: 3
Joined: Thu Dec 15, 2022 5:45 pm

Re: Motor shield - use variable to pass "FORWARD" or "BACKWARD"

Post by Coopsta »

Thankyou so much!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”