Go Down

Topic: Linking to C++ includes, or having a Dictionary or List template? (Read 4937 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

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.


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:

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131