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

From Medien Wiki
No edit summary
Line 19: Line 19:




''void setMotorSpeed(int newSpeed, int forwardPin, int reversePin, int throttlePin){
[[File:OOPARD1.jpg]]
// should it spin forwards or backwards?
 
if(newSpeed>0){
[[File:OOPARD2.jpg]]
//spin forwards
digitalWrite(reversePin,LOW);
digitalWrite(forwardPin,HIGH);
}else{
//spin backwards
digitalWrite(forwardPin,LOW);
digitalWrite(reversePin,HIGH);
}
//adjust the speed:
analogWrite(throttlePin, newSpeed);
}''




Line 49: Line 38:


It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.
It would be ideal to find a way of calling a certain function that only offers the most useful parameters (like setting the speed) and which handles technical details (switching pins on and off) internally.


==Possible solution: Data and code in one package „Classes“ and „Objects“==
==Possible solution: Data and code in one package „Classes“ and „Objects“==