|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Motor drive function?
Lets say I want to have a function, that somehow modifies an inputted speed and sets an inputted motor to that speed. Instinct tells me it would be something similar to
Code:
void Drive(int motor, unsigned char speed)
{
// modify inputted speed
motor = speed;
}
Drive(pwm01, 100);
What is the cause of this problem? How can I fix it? |
|
#2
|
|||||
|
|||||
|
Re: Motor drive function?
You need to pass the parameter that will be changed in by address rather than value.
Code:
void Drive(int *motor, unsigned char speed)
{
// modify inputted speed
*motor = speed;
}
Drive(&pwm01, 100);
|
|
#3
|
||||
|
||||
|
Re: Motor drive function?
Quote:
I think that you are mixing C++ with C. in C++, "int&" is a pass by reference. In C there is no pass by reference only pass by value and a pointer is the only way to do it. Mike To All, Mark's post is correct. Please read K&R chapter 5 before sliding down the perilous and provocative path of pointers. Mike |
|
#4
|
|||
|
|||
|
Re: Motor drive function?
Quote:
Last edited by Keith Watson : 15-02-2006 at 12:20. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Loop time for OperatorControl function? Debug blows... | Chris_Elston | Programming | 10 | 13-02-2006 14:42 |
| Arcade Function | gabrielse | Programming | 1 | 08-02-2006 00:49 |
| TTL port to a serial port on a demo board | ImmortalAres | Programming | 16 | 09-07-2005 23:44 |
| RoboEmu2(code simulator)--now with C! | rbayer | Programming | 23 | 17-02-2005 09:17 |
| heres the code. y this not working | omega | Programming | 16 | 31-03-2004 15:18 |