171
edits
Diannamertz (talk | contribs) mNo edit summary |
Diannamertz (talk | contribs) mNo edit summary |
||
Line 19: | Line 19: | ||
====Arduino==== | ====Arduino==== | ||
<source lang="java"> | <source lang="java"> | ||
int | int sensePin = 1; // infrared sensor to analog pin | ||
int | int value; // value coming from the sensor | ||
void setup() { | void setup() { | ||
Serial.begin(9600); | Serial.begin(9600); // start the serial port | ||
} | } | ||
void loop() { | void loop() { | ||
int value = analogRead(sensePin); // current value of the sensor | |||
byte scaledVal = map(value, 0, 600, 0, 255); // rescale to send as one byte | |||
Serial. | Serial.write(scaledVal); //print the distance | ||
delay(100); // arbitrary wait time | |||
} | } | ||
</source> | </source> | ||
====Processing==== | ====Processing==== | ||
<source lang="java"> | <source lang="java"> | ||
Serial myPort; | Serial myPort; // variable for the serial | ||
import processing.serial.*; // reads information coming in through the server via Arduino | |||
import processing.serial.*; | int incomingVal; // incoming number value | ||
int incomingVal; | int r; // example | ||
int b; // example | |||
int r; | int q; // example | ||
int b; | int o; // example | ||
int q; | |||
int o; | |||
void setup(){ | void setup(){ | ||
size(255,255); | size(255,255); // visualization window size | ||
myPort = new Serial(this,"/dev/tty.usbmodem411",9600); // my Arduino port | |||
myPort = new Serial(this,"/dev/tty.usbmodem411",9600); | |||
} | } | ||
void draw(){ | void draw(){ | ||
background(0); | background(0); // background black for visualization | ||
while(myPort.available() > 0){ | while(myPort.available() > 0){ | ||
incomingVal = myPort.read(); | incomingVal = myPort.read(); // while new data coming in from Arduino, store in variable | ||
} | } | ||
float reVal =map(incomingVal, 51, 255, 0, 255); // rescale the incoming value to the depth of the container | |||
fill( | fill(reVal); // fill the visualization with the rescaled incoming value | ||
rect(0, | rect(0,height - reVal,width,height); // draws rectangle of the incoming value | ||
println("Pasta:" +(reVal)+ " Rice:" + r+ " Bulgar:" + b+ " Quinoa:" + q+ " Oats:" + o ); // incoming value to be seen in console | |||
PrintWriter output = createWriter("data/data.tsv"); | PrintWriter output = createWriter("data/data.tsv"); // send info to external file | ||
output.println("Pasta:" + | output.println("Pasta:" +(reVal)+ " Rice:" + r+ " Bulgar:" + b+ " Quinoa:" + q+ " Oats:" + o ); // directs which information to be written to new file | ||
output.flush(); | output.flush(); // write the info | ||
} | } | ||
</source> | </source> | ||
====PHP==== | ====PHP==== |
edits