GMU:Functions and Classes (Arduino): Difference between revisions

From Medien Wiki
Line 90: Line 90:




''
[[OOPARD6.jpg]]
class MotoMamaMotor {
...
private: // the following definitions are only of „internal use“ for the class itself     
int forwardPin; //  c
int reversePin;
int throttlePin;
...
};
''




Line 106: Line 97:




''
[[File:OOPARD7.jpg]]
class MotoMamaMotor {
private:
...
public: //  we want the setup-function to be accessible from the outside.
void setup (int newForwardPin, int newReversePin, int newThrottlePin){
// we remember the pins for future use         
forwardPin=newForwardPin;
reversePin=newReversePin;
throttlePin=newThrottlePin;
// and at the same time we initialize the outputs !
digitalWrite(throttlePin,LOW); //  so that the motors don’t spin directly from the beginning ..
pinMode(forwardPin,OUTPUT);
pinMode(reversePin,OUTPUT);
pinMode(throttlePin,OUTPUT);
}
...
};
''


==A complete example ==
==A complete example ==