EasyManua.ls Logo

SunFounder GalaxyRVR - Page 47

Default Icon
120 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder GalaxyRVR Kit for Arduino, Release 1.0
(continued from previous page)
SoftPWMSet(in1, 0);
SoftPWMSet(in2, 255);
}
In the code above, we first add SoftPWM.h to the top of the code, enabling us to use the functions
in the SoftPWM library directly.
Then, initialize the SoftPWM library with SoftPWMBegin() function.
Finally, in the loop() function, we use SoftPWMSet() to assign different values to in1 and
in2, setting the motor in motion. You will notice the effect is similar to directly using LOW and
HIGH, but here we use numerical values within a range of 0~255.
Remember, in the world of Arduino, speed is expressed as a value between 0 (like a car at a stop
sign) and 255 (zooming down the highway!). So, when we say SoftPWMSet(in2, 255), were
telling that motor to go full speed ahead!
3. Now, let’s enter other values and observe any differences in motor speed.
#include <SoftPWM.h>
const int in1 = 2;
const int in2 = 3;
void setup() {
SoftPWMBegin();
}
void loop() {
SoftPWMSet(in1, 0);
for (int i = 0; i <= 255; i++) {
SoftPWMSet(in2, i);
delay(100);
}
delay(1000);
}
In the code above, we use a for loop to increment a variable i up to 255. The for loop in C language
is used to iterate over a part of the program several times. It consists of three parts:
3.4. Lesson 4: Mastering the TT Motor 43

Related product manuals