Dial Phidget
The Dial Phidget measures the position of the center dial. You can turn the dial clockwise or counter-clockwise continuously. When turning clockwise, the position will increase, and when turning counterclockwise, the position will decrease.
The Dial Phidget also has a button. The button operates similarly to the buttons on your Getting Started Kit. It returns true when pushed, and false when released.

Code (Java)
Create a file called Dial and insert the following code. Run your code. Move the dial to see the output change.
Not your programming language? Set my language and IDE.
package dial;
//Add Phidgets Library
import com.phidget22.*;
public class Dial {
public static void main(String[] args) throws Exception {
//Create
Encoder dial = new Encoder();
DigitalInput button = new DigitalInput();
//Open
dial.open(1000);
button.open(1000);
//Use your Phidget
while (true) {
System.out.println("Button State: " + button.getState());
System.out.println("Dial Position: " + dial.getPosition());
Thread.sleep(100);
}
}
}
//Add Phidgets Library
import com.phidget22.*;
public class Dial {
public static void main(String[] args) throws Exception {
//Create
Encoder dial = new Encoder();
DigitalInput button = new DigitalInput();
//Open
dial.open(1000);
button.open(1000);
//Use your Phidget
while (true) {
System.out.println("Button State: " + button.getState());
System.out.println("Dial Position: " + dial.getPosition());
Thread.sleep(100);
}
}
}
//Add Phidgets Library
import com.phidget22.*;
//Define
Encoder dial;
DigitalInput button;
void setup(){
try{
//Create
dial = new Encoder();
button = new DigitalInput();
//Open
dial.open(1000);
button.open(1000);
}catch(Exception e){
e.printStackTrace();
}
}
void draw(){
try{
//Use your Phidgets
System.out.println("Button Press: " + button.getState());
System.out.println("Dial Position: " + dial.getPosition());
delay(250);
}catch(Exception e){
e.printStackTrace();
}
}
Code (Python)
Create a file called Dial and insert the following code. Run your code. Move the dial to see the output change.
Not your programming language? Set my language and IDE.
#Add Phidgets Library
from Phidget22.Phidget import *
from Phidget22.Devices.Encoder import *
from Phidget22.Devices.DigitalInput import *
#Required for sleep statement
import time
#Create
dial = Encoder()
button = DigitalInput()
#Open
dial.openWaitForAttachment(5000)
button.openWaitForAttachment(5000)
#Use your Phidgets
while(True):
print("Button State: " + str(button.getState()))
print("Dial Position: " + str(dial.getPosition()))
time.sleep(0.25)
Code (C#)
Create a file called Dial and insert the following code. Run your code. Move the dial to see the output change.
Not your programming language? Set my language and IDE.
//Add Phidgets Library
using Phidget22;
namespace Dial
{
class Program
{
static void Main(string[] args)
{
//Create
Encoder dial = new Encoder();
DigitalInput button = new DigitalInput();
//Open
dial.Open(1000);
button.Open(1000);
//Use your Phidgets
while (true)
{
System.Console.WriteLine("Button State: " + button.State);
System.Console.WriteLine("Dial Position: " + dial.Position);
System.Threading.Thread.Sleep(250);
}
}
}
}
Code (Swift)
Create a file called Dial and insert the following code. Run your code. Move the dial to see the output change.
Not your programming language? Set my language and IDE.
You will need to add three Labels.
Coming Soon!
Applications
Dials are widely used on devices and machines to allow user input and control. Some examples include car stereos, audio control panels, microwave ovens, and many robotics applications.



Practice
Use the Dial Phidget’s direction information to turn on your LEDs. Attach your Dial Phidget to your VINT Hub in your Getting Started Kit. Write a program to turn on the green LED when the position is positive and turn on the red LED when the position is negative.
Check out the advanced lesson Using the Sensor API before you use the API for the first time.