SunFounder GalaxyRVR Kit for Arduino, Release 1.0
Slider D: 105
WS+null
Slider D: 105
WS+null
Slider D: 105
WS+null
6. Let the Slider control the tilt mechanism.
Now that we know the values transmitted by the slider widget, we can directly use these values
to rotate the servo.
Therefore, based on the previous code, add the following lines to initialize the servo and write
the slider’s value to the servo.
...
#include <Servo.h>
Servo myServo; // create a servo object
myServo.write(int(sliderD)); // control the servo to move to the current␣
˓→angle
...
void onReceive() {
...
myServo.write(int(sliderD)); // control the servo to move to the␣
˓→current angle
}
void setup() {
...
myServo.attach(6); // attaches the servo on pin 6
...
}
Here is the complete code:
Upload the above code to the GalaxyRVR, repeat steps 4 and 5 above, reconnect to the GalaxyRVR
LAN and re-run in the SunFounder Controller, then you can slide the slider to control the rover’s tilt
mechanism.
Now you’ve successfully learned to implement the SunFounder Controller and how to use the slider widget to control
servo movements. This process will allow you to interact with your GalaxyRVR in a more intuitive and direct way.
Step 4: Reflection and Summary
Using the SunFounder Controller to operate your Mars Rover may seem a bit complicated at first. Every time you
modify your code, you’ll need to repeat the following steps:
• Prior to uploading the code, ensure the switch is turned to the right.
3.11. Lesson 11: Exploring the Mars Rover Visual System - Camera and Real-time Control 93