|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Pointer to pwm
I just wanted to make sure this was safe to do.
Code:
typedef struct
{
// stuff
unsigned char* pwm;
} Motor;
void InitMotor( Motor* motor, unsigned char* pwm, /* more parameters */ )
{
// stuff
motor->pwm = pwm;
}
then if I want to change the motor speed
Motor myMotor; InitMotor( myMoter, pwm10 );
myMotor.pwm = 127; // set it to nuetral
Thanks |
|
#2
|
|||
|
|||
|
Re: Pointer to pwm
Code:
typedef struct
{
// stuff
unsigned char* pwm;
} Motor;
void InitMotor( Motor* motor, unsigned char* pwm, /* more parameters */ )
{
// stuff
motor->pwm = pwm;
}
then if I want to change the motor speed
Motor myMotor; InitMotor( &myMotor, &pwm10 );
*myMotor.pwm = 127; // set it to nuetral
Last edited by dcbrown : 05-02-2008 at 20:12. |
|
#3
|
|||
|
|||
|
Re: Pointer to pwm
Nope, you're right!
Thanks Last edited by bronxbomber92 : 05-02-2008 at 20:24. |
|
#4
|
||||
|
||||
|
Re: Pointer to pwm
that seems like an OK way to do it... what might end up being easier, though, is to just do something like:
#define leftMotor pwm01 #define rightMotor pwm02 then you can use your left and right motors wherever you want, and if someone plugs something in backwards and doesn't want to unplug it you just have to change it in the one location in the header file. Just another option to consider! |
|
#5
|
||||
|
||||
|
Re: Pointer to pwm
We use Left(int) and Right(int)
Code:
void Left(int speed) {
pwm01 = speed;
if(pwm01 > 254) {
pwm01 = 254;
} else if(pwm01 < 1) {
pwm01 = 1;
}
}
![]() |
|
#6
|
|||
|
|||
|
Re: Pointer to pwm
Quote:
![]() |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Suspicious pointer conversion | ebowla | Programming | 2 | 26-01-2008 12:13 |
| laser pointer | 1574aviad | Technical Discussion | 9 | 20-02-2005 20:25 |
| pwm 13-15 | wayne 05 | Programming | 2 | 04-10-2003 12:08 |
| PWM | Antonio | Technical Discussion | 21 | 06-01-2003 14:44 |
| Pwm | VanWEric | Programming | 17 | 01-11-2002 16:07 |