My project is to create a robot Arduino flower with two sensors: light and pressure, that opens and closes according to the values in those two sensors, and at the same time plays different videos through Processing according to those values.
I've been having a really hard time passing on the value from the analog sensors in Arduino too processing. This is what I have so far:
Arduino
#include <Servo.h>
Servo myservo;
int pressure = 0;
int light = 1;
int pre;
int val;
void setup()
{
Serial.begin(9600);
myservo.attach(2);
}
void loop() {
pre = analogRead(pressure);
pre = map(pre, 918, 1023, 255, 0);
val = analogRead(light);
val = map(val, 0, 255, 0, 127);
Serial.print(val, DEC);
/*if (val>50) {
Serial.print(1);
}
else {
Serial.print(0);
}*/
myservo.write(val);
}
Processing
import processing.video.*;
import processing.serial.*; //arduino
Serial myPort; // Create object from Serial class
int val;
Movie movie;
void setup() {
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
size(640, 360);
background(0);
movie = new Movie(this, "transit.mov");
movie.loop();
}
void movieEvent(Movie m) {
m.read();
}
void draw() {
val = myPort.read();
println(val);
//if (movie.available() == true) {
// movie.read();
//}
image(movie, 0, 0, width, height);
if (val==49) {
movie.jump(1);
}
}
For now I'm just trying to make the video react to the light sensor, but haven't been able. All I get from the Processing readings is 48. The motor reacts fine to the sensors.