EasyManua.ls Logo

SunFounder GalaxyRVR - Page 45

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)
pinMode(in4, OUTPUT);
}
void loop() {
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(2000);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
delay(2000);
digitalWrite(in3, HIGH);
digitalWrite(in4, HIGH);
delay(5000);
}
Here we use the delay() function to make the Arduino pause for a certain amount of time,
much like taking a short nap in the middle of our story.
In the code, we use the “Brake” state to stop the motor, and you’ll notice that the motor stops
abruptly. Try setting both pins to LOW to test the “Standby” state, and you’ll find that the
motor gradually slows down to a stop.
Now that you should have a better understanding of how the motor driver chip controls the motors through the
GalaxyRVR Shield and how we can use Arduino code to manipulate the motor’s movements. Isn’t it fascinating how
a few lines of code can dictate the behavior of a physical object like our motor?
Consider the following questions as you move forward:
If we move all the code from the loop() function into the setup() function, how would the behavior of the
motor change?
How would you modify the code to control six motors simultaneously?
Remember, the more you experiment and play around with your code, the more you learn. Feel free to tweak, modify,
and optimize your code as you deem fit. Happy coding!
Step 4: Controlling Motor Speed
In the previous step, we controlled the motor’s direction by simply setting its pins HIGH or LOW. This is like giving
the motor full power to drive it, similar to pressing the accelerator pedal to the floor in a car. But in many situations,
we might want to adjust the motor speed to suit different scenarios, just like we adjust the speed of a car depending on
whether we’re driving in a city or on a highway. This is where Pulse Width Modulation (PWM) comes in.
3.4. Lesson 4: Mastering the TT Motor 41

Related product manuals