Go Down

Topic: Linking to C++ includes, or having a Dictionary or List template? (Read 3768 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.
Please post technical questions on the forum, not by personal message. Thanks!

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

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!

Arduino
via Egeo 16
Torino, 10131
Italy