GMU:Speculative Atmospheres II/Betül: Difference between revisions

From Medien Wiki
No edit summary
No edit summary
Line 55: Line 55:
<source style="border:none; height:650px; overflow:scroll;" lang="c" line start="55" highlight="4">
<source style="border:none; height:650px; overflow:scroll;" lang="c" line start="55" highlight="4">


import processing.serial.*;
import processing.serial.*;     // import Serial library
Serial myPort;          
Serial myPort;                 // Create object from Serial class
String incomingData = null;  
String incomingData = null;     // create String "text" variable for incoming arduino data
float rawSensorData = 0;         
float rawSensorData = 0;        // create float "number" variable for incoming arduino data
float r,g,b;
boolean buttonPressed;
boolean buttonPressed;
boolean pastButtonData = false, currentButtonData = false;
boolean pastButtonData = false, currentButtonData = false;
Line 64: Line 65:
//tıme and date
//tıme and date
int h,m,s;
int h,m,s;
String dataName = "positions2601";  
String dataName = "positions2601"; // **** assign a filename
String folderName = "folder01";  
String folderName = "folder01"; // **** assign a folder name
int imgCounter = 0;
int imgCounter = 0;


void setup() {
void setup() {
   size(500, 500);                          
   size(500, 500);                             // define the size of the canvas
   String portName = Serial.list()[2];      
   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);   
   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');                   
   myPort.bufferUntil('\n');                  // receive data until new line character comes up
   background (255);                           
   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");  
   output = createWriter("/Users/machd/Desktop/speculative atmospheres II : final/"+folderName+"/"+dataName+".txt");  
}
}
Line 79: Line 80:


void draw() {
void draw() {
//*** experiment here to visualize your sensor data!
//*** experiment here to visualize your sensor data
//*** use the variable – rawSensorData – to change things according to sensor changes.
//*** use the variable – rawSensorData – to change things according to sensor changes.


Line 94: Line 95:
// it allows you to use the incoming data in the draw() function, you do not need to change this.
// it allows you to use the incoming data in the draw() function, you do not need to change this.
void serialEvent(Serial myPort) {
void serialEvent(Serial myPort) {
   incomingData = myPort.readString();    
   incomingData = myPort.readString();         // read the incoming data as String and save it in the "incomingData" variable
   r = float(trim(incomingData.split(" ")[0]));
   r = float(trim(incomingData.split(" ")[0]));
   g = float(trim(incomingData.split(" ")[1]));
   g = float(trim(incomingData.split(" ")[1]));
Line 111: Line 112:
   }
   }
    
    
   //rawSensorData = float(trim(incomingData));   
   //rawSensorData = float(trim(incomingData));  // clean the incoming data String and convert it to a float data type (a number)
   //println (rawSensorData);                
   //println (rawSensorData);                   // print the data to the console for inspection
   println (incomingData);
   println (incomingData);
   myPort.clear();                          
   myPort.clear();                             // clear the serial port for receiving new data
   pastButtonData = currentButtonData;
   pastButtonData = currentButtonData;
}
}


void getTime(){
void getTime(){
 
//get the current tıime
h=hour();
h=hour();
m=minute();
m=minute();
Line 125: Line 126:
//println(h,m,s);
//println(h,m,s);
String time = str(h)+":"+str(m)+":"+str(s)+ "-" + str(buttonPressed);
String time = str(h)+":"+str(m)+":"+str(s)+ "-" + str(buttonPressed);
 
//println (time);
}
}


Line 131: Line 132:
   output.close();
   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>
</source>