From BlueMelon
This application framework demonstrates:
- Initialization of a Master device.
- Setup one or more specific BlueSense modules.
- Stopping BlueSense
Refer to the individual examples for examples of specific BlueSense modules.
// import library
import org.bluemelon.bluesense.*;
// Master device always needed
Master master;
// examples of sensor, actuator devices
SwitchInputDevice swin;
ServoDevice srvDev;
....
// id's of devices
int switchId = 100;
int servoId = 1201;
.....
boolean setupDevices() {
// try to find the device within the next 5 seconds
Device dev = master.detectDevice(switchId, 5 * 1000 * 1000);
// device not found?
if(dev==null) {
System.err.println("Device "+switchId+" not found!\n");
return false;
}
swin = (SwitchInputDevice)dev;
dev = master.detectDevice(servoId, 5 * 1000 * 1000);
// device not found?
if(dev==null) {
System.err.println("Device "+servoId+" not found!\n");
return false;
}
srvDev = (ServoDevice)dev;
// detect other devices
......
// do some configuration here
// setup pins as rotary input
swin.requestNeedsRotary(rport, true);
......
return true;
}
// setup master device
void setup() {
swin = null;
master = new Master();
if (setupDevices()) {
// call yield every 1 ms.
master.start(1);
}
size(200,200);
framerate(50);
}
// For example interact with your devices in the draw function
void draw()
{
srvDev.......
switchIn......
}
public void stop() {
System.out.println("stopping...");
master.close();
System.out.println("stopped");
}