|
|
(19 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| ==Use our examples==
| | #REDIRECT [[Language - Python]] |
| One of the best ways to start programming with Phidgets is to use our example code as a guide. Before we get started, make sure you have read [[#Install Phidget Python module for Windows| how to install the Phidget Python module]] section above.
| |
| | |
| | |
| Now that you have Python and the Phidget Python module installed, select an example that will work with your Phidget:
| |
| *{{SampleCode|Python|Python Examples}}
| |
| | |
| | |
| Right-click on the example and open it in IDLE:
| |
| [[Image:Python_idle_open.png|link=|center]]
| |
| | |
| | |
| To run the example, simply click on ''Run'' and select ''Run Module'':
| |
| [[Image:Python_idle_run.png|link=|center]]
| |
| | |
| Ensure that PhidgetHelperFunctions.py is in the same folder as the example.
| |
| | |
| {{Edit_the_Examples}}
| |
| | |
| ==Setting Up a New Script==
| |
| When you are building a script from scratch, or adding Phidget functionality to an existing script, you'll need to configure your program to properly link the Phidget Python library.
| |
| | |
| | |
| To include the Phidget Python library, add the following line to your code:
| |
| | |
| <syntaxhighlight lang=python>
| |
| from Phidget22.PhidgetException import *
| |
| from Phidget22.Phidget import *
| |
| </syntaxhighlight>
| |
| | |
| Then, you will also have to add a reference to your particular Phidget. For example, you would include the following line for a DigitalInput:
| |
| | |
| <syntaxhighlight lang=python>
| |
| from Phidget22.Devices.DigitalInput import *
| |
| </syntaxhighlight>
| |
| | |
| You can now compile the file as shown in the previous section.
| |
| | |
| The project now has access to Phidgets.
| |