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!
Motor shield - use variable to pass "FORWARD" or "BACKWARD"
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Coopsta
- Posts: 3
- Joined: Thu Dec 15, 2022 5:45 pm
- adafruit_support_carter
- Posts: 29176
- Joined: Tue Nov 29, 2016 2:45 pm
Re: Motor shield - use variable to pass "FORWARD" or "BACKWARD"
The run method takes a uint8_t (unsigned integer):
https://adafruit.github.io/Adafruit_Mot ... e37d4e518c
You are trying to pass it a string.
https://adafruit.github.io/Adafruit_Mot ... e37d4e518c
You are trying to pass it a string.
- Coopsta
- Posts: 3
- Joined: Thu Dec 15, 2022 5:45 pm
Re: Motor shield - use variable to pass "FORWARD" or "BACKWARD"
Thanks for looking.
How can the command "FORWARD" be a uint8_t? Is it possible for these run commands to be a variable?
How can the command "FORWARD" be a uint8_t? Is it possible for these run commands to be a variable?
- adafruit_support_bill
- Posts: 88097
- Joined: Sat Feb 07, 2009 10:11 am
Re: Motor shield - use variable to pass "FORWARD" or "BACKWARD"
The commands are defined in the header file like this:
You can pass the command as a variable. But the variable needs to be an integer type. Ideally uint8_t.
Code: Select all
#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4
- Coopsta
- Posts: 3
- Joined: Thu Dec 15, 2022 5:45 pm
Re: Motor shield - use variable to pass "FORWARD" or "BACKWARD"
Thankyou so much!
Please be positive and constructive with your questions and comments.