generated from processing/processing-library-template-ant
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
8,471 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="bin" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="output" path="resources/code"/> | ||
</classpath> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="bin" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="lib" path="C:/Program Files/processing-3.5.4/core/library/core.jar"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="lib" path="C:/Program Files/Phidgets/Phidget22/phidget22.jar"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="resources/code"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
examples/Advanced/Digital_Input_Event/Digital_Input_Event.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
This example demostrates the use of events when connecting a digital input to a hub. | ||
The use of the "stateChange" event is similar to the use of "keyPressed" with one difference: | ||
The "stateChange" event will be called both when the button is pressed and when it is depressed. Ths means, if you want to detect only a press, you should check its state inside the event, | ||
as show below in the code. | ||
If you have multiple buttons (or switches etc.) and you need to know which one triggered the event, you should use stateChange(Channel ch) - see example Multiple_Sensors_Events | ||
*/ | ||
|
||
import shenkar.phidgets4processing.*; | ||
|
||
Channel myButton; | ||
|
||
void setup() { | ||
size(200, 400); | ||
// using a VINT hub port 2 as digital input: connect button terminals to "data" and "ground" pins of the port | ||
myButton = new Channel(this, "HUB0000", 2, "digitalInput"); | ||
background(0); | ||
} | ||
|
||
void draw() { | ||
} | ||
|
||
void stateChange() { | ||
if (myButton.read() == 1) { | ||
ellipse (100, 200, 100, 100); | ||
} | ||
else { | ||
background(0); | ||
} | ||
} | ||
|
||
/* | ||
All functions for digitalInput channel: | ||
read() - most basic way to use the channel. returns 0 or 1 (int) | ||
getState() - get state sensed by the device as boolean (true or false) | ||
Event functions: | ||
void stateChange() - called when the channel detects a change in state. See example Digital_Input_Event | ||
void stateChangeRT() - real-time version of the event. See https://github.com/sgeigers/Phidgets4Processing | ||
Specipic functions for using with DAQ1400 - Versatile Input Phidget: | ||
getInputMode() - for some devices, returns whether input mode is NPN or PNP. Returns a String (e.g. "PNP") | ||
setInputMode(String) - for some devices, sets whether input mode is NPN or PNP | ||
getPowerSupply() - for some devices, returns power supply in Volts: 12, 24 or 0 for OFF | ||
setPowerSupply(int) - for some devices, sets power supply in Volts: 12, 24 or 0 for OFF | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
This example demonstrates opening multiple sensors connected to 2 hubs. | ||
*/ | ||
|
||
import shenkar.phidgets4processing.*; | ||
|
||
Channel myLightSensor; | ||
Channel mySlider; | ||
Channel mySoundSensor; | ||
|
||
void setup() { | ||
size(400, 400); | ||
mySlider = new Channel(this, "1112", 619570, 3); // open a channel for 60mm slider 1112 on port 3 of hub w/ serial number 619570 | ||
mySoundSensor = new Channel(this, "SND1000", 619570, 0); // open a channel for sound phidget on port 0 of hub w/ serial number 619570. If we connect more than 1 sensor to a hub, it's better to specify the port number | ||
myLightSensor = new Channel(this, "1142", 561918); // open a channel for light sensor 1142 on port 0 of hub w/ serial number 561918 | ||
|
||
rectMode(CENTER); | ||
noStroke(); | ||
} | ||
|
||
void draw() { | ||
background(0); | ||
|
||
// reading sensors to float variables | ||
float snd = mySoundSensor.read(); | ||
float sld = mySlider.read(); | ||
float light = myLightSensor.read(); | ||
|
||
// drawing a dancing "star" | ||
translate(width/2, height/2); | ||
for (int i=0; i<12; i++) { | ||
pushMatrix(); | ||
translate (width/4,0); | ||
rotate(snd/500*PI); | ||
fill (light/4, 167, 134); | ||
rect (0, 0, sld/10, 5); | ||
popMatrix(); | ||
rotate(PI/4); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
examples/Advanced/Multiple_Sensors_Events/Multiple_Sensors_Events.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
This example demonstrates using events when more than 1 "simple sensor" is connected. | ||
The event can be called by any of the opened channels of an applicable type (e.g "sensorChange()" might be triggered by any simple sensor). | ||
To know which channel triggerd the event, we add (Channel ch) to creating the event (see below). Then we can compare ch to relevant opened channels and know which one triggered the event. | ||
We can also use this ch for getting data from the channel which triggered the event. If we know which channel it is, this is equivalent to using the channel name itself. | ||
*/ | ||
|
||
|
||
import shenkar.phidgets4processing.*; | ||
|
||
Channel myProximitySensor; | ||
Channel myTouchSensor; | ||
|
||
void setup() { | ||
size(200, 200); | ||
myTouchSensor = new Channel(this, "1129", 619570, 2); // open a channel for touch sensor 1129 on port 2 of hub w/ serial number 619570 | ||
myProximitySensor = new Channel(this, "1101", 409648, 4); // open a channel for proximity sensor adapter 1101 on analog channel 4 of interface kit w/ serial number 409648 | ||
myProximitySensor.setSensorType("2Y0A02"); // set sensor type for proximity sensor to 2Y0A02 (20 - 150cm) | ||
myTouchSensor.setReadChangeTrigger(500); // set the event to trigger only for changes of at least 500 (out of 1000) | ||
|
||
noStroke(); | ||
fill (100); | ||
} | ||
|
||
void draw() { | ||
background(0); | ||
if (myProximitySensor.getSensorValueValidity()) { // only draw the rect if the value from proimity sensor is in the valid range | ||
rect (50, myProximitySensor.getSensorValue(), 100, 20); | ||
} | ||
} | ||
|
||
void sensorChange(Channel ch) { | ||
if (ch == myTouchSensor) { // check which channel triggered the event | ||
if (ch.read() > 500) { // this touch sensor is semi-analog. will give a value of ~1000 if touched and 0 if not touched | ||
fill (255); | ||
} else { | ||
fill (100); | ||
} | ||
} | ||
} |
Oops, something went wrong.