Go Down

Topic: Linking to C++ includes, or having a Dictionary or List template? (Read 3 times) previous topic - next topic

visser


You can create a class that link a particular motor and speed value.

Code: [Select]
class motorWithSpeed
{
   int motorPin;
   int motorSpeed;

   motorWithSpeed(int pin);
   
   setSpeed(int speed);
   int getSpeed();
};


You can create an instance of that class:
Code: [Select]
motorWithSpeed speedy(3);

You can make that motor change speed:
Code: [Select]
speedy.setSpeed(160);

You can later determine how fast the motor is going:
Code: [Select]
int speedySpeed = speedy.getSpeed();

Only the class instance maintains the speed.



OMG, I didn't think of using a class! (herpaderp) Thankyou paul! I will love you forever <3

Nick Gammon

You used the word "object" in your very first post. And C++.

C++ is basically an object-oriented language. Objects are created by classes.

http://www.cplusplus.com/doc/tutorial/classes/

Quote
An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable.

Go Up