560
edits
Betulpeker (talk | contribs) No edit summary |
Betulpeker (talk | contribs) No edit summary |
||
Line 52: | Line 52: | ||
File:piecess.jpg | File:piecess.jpg | ||
</gallery> | </gallery> | ||
<source style="border:none; height:650px; overflow:scroll;" lang="c" line start="55" highlight="4"> | |||
import processing.serial.*; // import Serial library | |||
Serial myPort; // Create object from Serial class | |||
String incomingData = null; // create String "text" variable for incoming arduino data | |||
float rawSensorData = 0; // create float "number" variable for incoming arduino data | |||
float r,g,b; | |||
boolean buttonPressed; | |||
boolean pastButtonData = false, currentButtonData = false; | |||
PrintWriter output; | |||
//tıme and date | |||
int h,m,s; | |||
String dataName = "positions2601"; // **** assıgn a fiename | |||
String folderName = "folder01"; // **** assıgn a folder name | |||
int imgCounter = 0; | |||
void setup() { | |||
size(500, 500); // define the size of the canvas | |||
String portName = Serial.list()[2]; // define the serial port. change the number in [] to a 1 or 2 etc. to match your Arduino USB port. | |||
myPort = new Serial(this, portName, 9600); // create new serial object with baud rate (USB-speed) 9600 (must be the same in arduino!!!) | |||
myPort.bufferUntil('\n'); // receive data until new line character comes up | |||
background (255); // make a white background. You can also put this in DRAW to refresh your canvas every draw loop. | |||
output = createWriter("/Users/machd/Desktop/speculative atmospheres II : final/"+folderName+"/"+dataName+".txt"); | |||
} | |||
void draw() { | |||
//*** experiment here to visualize your sensor data! | |||
//*** use the variable – rawSensorData – to change things according to sensor changes. | |||
// call function time | |||
getTime(); | |||
// for example: | |||
//float mappedData = map (rawSensorData, 0, 1023, 0, 255); | |||
background (r,g,b); | |||
} | |||
// this is the serial function that runs constantly in the background of your program | |||
// it allows you to use the incoming data in the draw() function, you do not need to change this. | |||
void serialEvent(Serial myPort) { | |||
incomingData = myPort.readString(); // read the incoming data as String and save it in the "incomingData" variable | |||
r = float(trim(incomingData.split(" ")[0])); | |||
g = float(trim(incomingData.split(" ")[1])); | |||
b = float(trim(incomingData.split(" ")[2])); | |||
buttonPressed = boolean(int(trim(incomingData.split(" ")[3]))); | |||
currentButtonData = buttonPressed; | |||
if(pastButtonData == true && currentButtonData == false) { | |||
// Wrıte to fıle the current values | |||
String time = str(h)+":"+str(m)+":"+str(s); | |||
output.println(r + ":" + g + ":" + b + " Time:" + time); | |||
output.flush(); | |||
// Save an ımage of the current color | |||
save("/Users/machd/Desktop/speculative atmospheres II : final/" + folderName +"/"+ dataName +"_" +imgCounter +".jpg"); | |||
save("/Users/machd/Desktop/speculative atmospheres II : final/" + folderName +"/"+ dataName + "_" +imgCounter + ".png"); | |||
imgCounter = imgCounter + 1; | |||
} | |||
//rawSensorData = float(trim(incomingData)); // clean the incoming data String and convert it to a float data type (a number) | |||
//println (rawSensorData); // print the data to the console for inspection | |||
println (incomingData); | |||
myPort.clear(); // clear the serial port for receiving new data | |||
pastButtonData = currentButtonData; | |||
} | |||
void getTime(){ | |||
//get the current tıime | |||
h=hour(); | |||
m=minute(); | |||
s=second(); | |||
//println(h,m,s); | |||
String time = str(h)+":"+str(m)+":"+str(s)+ "-" + str(buttonPressed); | |||
//println (time); | |||
} | |||
void stop() { | |||
output.close(); | |||
} | |||
/* | |||
HELP: FINDING THE CORRECT USB PORT | |||
if you can not find your arduino USB port, make a new file and add this code: | |||
* CODE START * | |||
import processing.serial.*; | |||
// List all the available serial ports | |||
printArray(Serial.list()); | |||
* CODE END * | |||
It will print out a list of all your USB connections. | |||
Find the [ ] number for your Arduino Port and include it in line 8 of this code. | |||
*/ | |||
</source> | |||
edits