Arduino Code: (project 38 modified)
// Project 38
#define sensorPin 9
long pwmRange, inch, cm;
void setup() {
// Start serial communications
Serial.begin(9600);
pinMode(sensorPin, INPUT);
}
void loop() {
pwmRange = pulseIn(sensorPin, HIGH);
// 147uS per inch according to datasheet
inch = pwmRange / 147;
Serial.println(inch);
}
Processing Code: (an example I do not remember)
import processing.serial.*;
Serial myPort; // The serial port:
//one variable needed for the circle diameter
int circDiameter;
void setup() {
size(400, 300);
println(Serial.list());
// match the port correctly from the printed serial list
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
}
void draw() {
background(200);
fill(165, 27, 27);
ellipse(width/2, height/2, (circDiameter*10)-500, (circDiameter*10)-500);
}
void serialEvent(Serial myPort) {
// read String from the serial port:
String inString = myPort.readString();
println(inString);
float tempDiameter = float(inString);
//turn serial info into the circDiameter variable
circDiameter = int( map(tempDiameter, 0, 1023, 30, 250) );
}
No comments:
Post a Comment