Go Down

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


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]

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


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

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


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.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Go Up