Created
May 8, 2019 15:22
-
-
Save KayceeCC/e9499a4ae09f46f378ff68640f2446c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.serial.*; | |
import processing.video.*; | |
Capture cam; | |
int Size = 10; | |
Serial myPort; | |
int valueFromArduino; | |
int PORT_INDEX=5; | |
void setup() { | |
size(640, 480); | |
cam = new Capture (this, 640, 480); | |
cam.start(); | |
printArray(Serial.list()); | |
// this prints out the list of all available serial ports on your computer. | |
myPort = new Serial(this, Serial.list()[ PORT_INDEX ], 9600); | |
// WARNING! | |
// You will definitely get an error here. | |
// Change the PORT_INDEX to 0 and try running it again. | |
// And then, check the list of the ports, | |
// find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----" | |
// and replace PORT_INDEX above with the index number of the port. | |
} | |
void draw() { | |
if (cam.available()) { | |
cam.read(); | |
cam.loadPixels(); | |
} | |
while ( myPort.available() > 0) { | |
valueFromArduino = myPort.read(); | |
} | |
int a = int(map (valueFromArduino,200,1500,1,10)); | |
for (int y=0; y<cam.height; y+=a) { | |
for (int x=0; x<cam.width; x+=a) { | |
int i= y*cam.width+x; | |
fill( cam.pixels[i] ); | |
noStroke(); | |
ellipse(x, y, a, a); | |
} | |
} | |
//image(cam,0,0,width,height); | |
cam.updatePixels(); | |
// to read the value from the Arduino | |
println(valueFromArduino);//This prints out the values from Arduino | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IMA NYU Shanghai | |
// Interaction Lab | |
// This code sends one value from Arduino to Processing | |
void setup() { | |
Serial.begin(9600); | |
pinMode(pin, INPUT); | |
} | |
void loop() { | |
Serial.write(sensorValue); | |
uint16_t sensorValue = analogRead (pin); | |
double distance = get_IR (sensorValue); | |
Serial.println (sensorValue); | |
Serial.println (" cm"); | |
Serial.println (); | |
delay (500); | |
delay(10); | |
double get_IR (uint16_t sensorValue) { | |
if (sensorValue < 16) sensorValue = 16; | |
return 2076.0 / (sensorValue - 11.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment