Shared Phidgets Simple Example Controlling A Servo
<< Back to the SharedPhidgets 3 page
What you will learn in this tutorial:
- how to create a Shared Phidgets servo object,
- how to assign a specific serial number,
- how to use the servo skin to control a servo and
- how to control the servo from your source code.
Download source: SharedPhidgetsExamples.zip The zip file contains the program code of all the Shared Phidgets programming examples. The source code of this example can be found in the 'ServoExample' project. |
Overview

The Phidget Servo
- Create a new Shared Phidgets appliance with the template in VisualStudio.NET
- Create a servo object
- Create a servo skin and connect it to the servo object
- Controlling the servo object from the code directly (with 2 buttons on the form)
- Finished! Compile the application and test the control of the servo motor!
Step-by-step Instructions
Preparation: Install the Shared Phidgets toolkit on all client machines, run the Connector software, and attach at least one servo motor to one of the client computers.
1) Open VisualStudio.NET 2005, click New Project, select a new C# Windows application, enter a name for the project, and confirm the dialog.

2) Doubleclick the 'ApplianceForm.cs' file in the project explorer on the right side of the screen:

The windows form for the appliance control will now be opened:

It is possible to change the appliance name, as well as the default address for the connection to the shared dictionary by changing properties of the main form:


3) Drag a SharedPhidget Servo component on the appliance form.

It is possible to change the serial number of the servo. If you have only one servo at your infrastructure, you don't need to add the serial number because the component will then connect to the only hardware device of this type that it will find.

4) Create a skin object for the servo:

Change the servo object of the ServoSkin to the object of the created servo, here this is servo1

5) Create two additional buttons on the form, and change their Text property to "180 degrees" and "0 degrees".

Double click on the buttons, and add the following code to the button click handler:
for the 180-degree-button:
{
this.servo1.Motors[0].Position = 180;
}
for the 0-degree-button:
{
this.servo1.Motors[0].Position = 0;
}
6) Compile the application:

Finished!
It is now possible to use the graphical interface skin to control the servo, and to use the buttons to set the position of the servo to a particular position. From here, this simple application can now be modified and enhanced with additional functionality. You can add more servo objects if needed, but remember to specify the serial number for each of the servos.