Thank you very much for answering,
but it dos not work right now
For a better understanding i should send you the whole code:
import processing.video.*;
import processing.serial.*;
Capture cam;
Serial myPort; // Create object from Serial class
void setup() {
size(200, 160);
myPort = new Serial(this, Serial.list()[0], 115200, 'N', 8, 2.0);
String[] devices = Capture.list();
println(devices);
cam = new Capture(this, 10, 8, devices[2]);
}
void draw() {
rect(20,20,20,20); //rect(x, y, width, height)
noFill();
stroke(255);
frameRate(5);
if (cam.available() == true) {
cam.read();
cam.filter(GRAY);
image(cam,0,0,200,160); //image(img, x, y, width, height)
rect(21,21,2,2); //rect(x, y, width, height)
noFill();
stroke(255);
}
cam.loadPixels();
color grayData = get(22,22) ; // den pixel aus dem quadrat von rect...
int greyLevel = grayData & 0xFF;
println (" binary = "+binary(grayData)+" hex = "+hex(grayData,6)+ " byte = "+byte(grayData)); // als Beispiel : 11111111 01011101 01011101 01011101
things that can help. i got it from other kind discussions // byte b1 = (byte)(ceil(grayData) & 0xFF);
// byte b2 = (byte)( (ceil(grayData) >>> 8) & 0xFF );
// println (b1 +" "+b2);
// float grayDataToSend = ceil( map (grayData, 0, 255, 735, 2520)); myPort.write(0xAA);
myPort.write(0xA0);
myPort.write(0x55);
myPort.write(0x04);
myPort.write(1);
myPort.write(1);
myPort.write(25);
myPort.write(0xAA);
myPort.write(0xA0);
myPort.write(0x55);
myPort.write(0x03);
myPort.write(1);
myPort.write(1);
myPort.write(0);
myPort.write(0xAA);
myPort.write(0xA0);
myPort.write(0x55);
myPort.write(0x01);
myPort.write(0x01);
myPort.write(0x02);
myPort.write(0xDC); //
here must be the low byte myPort.write(0x02); //
and here the high byte of servoposition }
The reason for that, asking your self
I would like to control a position of a simple servo motor (from max to max angle position) by brightness values of a web cam (one pixel from white to black). It shall be a nice installation with interact moving parts.
For this i use a iMac and a SD84 USB controller (
http://www.robot-electronics.co.uk/htm/sd84tech.htm.
The problem is....i am a noob in Processing