Closing Phidgets
In this lesson, you will learn about closing your Phidget.

Write Code (Java)
Copy the code below into the project you created. If you don't have a project or forgot how to create one, revisit the Configure section.
Not your programming language? Set your preferences so we can display relevant code examples
Write Code (Python)
Copy the code below into the project you created. If you don't have a project or forgot how to create one, revisit the Configure section.
Not your programming language? Set your preferences so we can display relevant code examples
Write Code (C#)
Copy the code below into the project you created. If you don't have a project or forgot how to create one, revisit the Configure section.
Not your programming language? Set your preferences so we can display relevant code examples
Write Code (Swift)
Create a label in your window and copy the code below into the project you created. If you don't have a project or forgot how to create one, revisit the Configure section.
Not your programming language? Set your preferences so we can display relevant code examples
Create a label
Run Your Program
You will see the temperature displayed once and then your program will end.
What Does Closing My Phidget Do?
Closing your Phidget breaks the connection between your code and your physical device. This means that after calling close, your object can no longer be used in your code. Closing will also cause the device to return to its default state. For example, if you were powering an LED, the LED would turn off after closing, or, if you were controlling a motor, the motor would stop spinning after calling close.
When Should I Close My Phidget?
For most classroom projects, you won’t have to worry about closing your Phidgets. You may want to consider adding a close statement in the following situations:
- If power is a concern: When Phidgets are in their default state, they use much less power than when they are actively measuring/controlling. If you are using a battery to power your project, you may want to close your Phidget between uses to conserve energy.
- If you want to use your Phidget in multiple programs: A Phidget can only be open in one program at a time (unless you are using networked Phidgets). If you want to share the Phidget between multiple programs, you can close it when you are done.
- If memory is a concern: Creating objects takes up memory, so if you are only using your Phidget for a short period of time, consider closing the Phidget.
Practice
- Try printing temperature from your Phidget after the close call. What error do you get?
- Try calling open again after closing your Phidget. Can you print the temperature again?
Practice
- Try printing temperature from your Phidget after the close call. What error do you get?
- Try calling open again after closing your Phidget. Can you print the temperature again?
Practice
- Try printing temperature from your Phidget after the close call. What error do you get?
- Try calling open again after closing your Phidget. Can you print the temperature again?
Practice
- Are there any new data points after closing the Phidget?
- Try calling open again after closing your Phidget. Can you print the temperature again?