84
edits
Line 131: | Line 131: | ||
Before writing your code in Arduino, make sure that you have installed the library about OSC you need. Here I used the[https://github.com/CNMAT/OSC OSC library] written from University of Berkeley. | Before writing your code in Arduino, make sure that you have installed the library about OSC you need. Here I used the[https://github.com/CNMAT/OSC OSC library] written from University of Berkeley. | ||
Basically, the code below has the function of receiving data from Captury via OSC, and the speed data of the tracked person's movement will control the value of photocell sensor, which will trigger the vibration motor at the same time. | |||
'''The Code Controlling with Captury:''' | '''The Code Controlling with Captury:''' | ||
Line 141: | Line 143: | ||
#include <SPI.h> | #include <SPI.h> | ||
#include <OSCBoards.h> | #include <OSCBoards.h> | ||
#include <OSCBundle.h> | |||
EthernetUDP Udp; | EthernetUDP Udp; | ||
Line 150: | Line 153: | ||
//destination IP | //destination IP | ||
IPAddress outIp(128, 32, 122, 125); | IPAddress outIp(128, 32, 122, 125); | ||
OSCMessage msg; | |||
//SLIPEncodedSerial SLIPSerial; | |||
//port numbers | //port numbers | ||
const unsigned int inPort = 1065; | const unsigned int inPort = 1065; | ||
Line 171: | Line 175: | ||
//Recording the original position and running time | //Recording the original position and running time | ||
x1 = msg.getFloat(0); | x1 = msg.getFloat(0); | ||
z1 = msg.getFloat(1); | z1 = msg.getFloat(1); | ||
Line 181: | Line 185: | ||
void OscMsg(OSCMessage &msg){ | void OscMsg(OSCMessage &msg){ | ||
//Using SLIPSerial to get serial data | |||
/* while(!SLIPSerial.endofPacket()) | |||
{ | { | ||
int size = SLIPSerial.available(); | int size = SLIPSerial.available(); | ||
Line 200: | Line 203: | ||
{ | { | ||
//get that String | //get that String | ||
int data = msg.getString(0); | |||
}*/ | }*/ | ||
OSCBundle bundleIN; | |||
int size; | |||
if( (size = Udp.parsePacket())>0) | |||
{ | |||
while(size--) | |||
bundleIN.fill(Udp.read()); | |||
if(!bundleIN.hasError()) | |||
//OSCMessages can be routed to a specific function(GetPosition) by matching their address partial | |||
bundleIN.route("/blender/Root/vector",GetPosition); | |||
} | |||
} | |||
void GetPosition(OSCMessage &msg) | void GetPosition(OSCMessage &msg){ | ||
//Recording the distance between two points | //Recording the distance between two points | ||
float x = msg.getFloat(0); | float x = msg.getFloat(0); | ||
Line 232: | Line 245: | ||
} | } | ||
void loop() | void loop(void) { | ||
// | //photocellReading = analogRead(photocellPin); | ||
//Giving the velocity to | //Giving the velocity to 马达 | ||
OscMsg( | OscMsg(msg); | ||
photocellReading = vel; | |||
if(photocellReading < 600){ | if(photocellReading < 600){ | ||
Line 249: | Line 262: | ||
Serial.print("Analog reading = "); | Serial.print("Analog reading = "); | ||
Serial.println(photocellReading); // the raw analog reading | Serial.println(photocellReading); // the raw analog reading | ||
delay(10); | delay(10); |
edits