fahrnisurf
YaBB Newbies
Offline
Posts: 1
worse code or is arduino really that slow
Oct 13th , 2008, 10:35am
The following sketch should capture a video signal from a DV cam, check if a pixel fulfills a condition (brightness), then give a response. The patch works fine as I see the response in time on my screen. But the same responde should also be sent to arduino. Now it's getting strange. Arduino gives respones when I start the patch,after ~1 sec nothing. I'm not a efficient programmer so maybe my code is crap/too slow. Or is the arduino-processing communication crapy. Thanks for any hint. import JMyron.*; import processing.serial.*; import cc.arduino.*; Arduino arduino; JMyron m; //fixe pixelpositionen für notengrabbing int x_gr = 172; int x_ro = 286; int x_ge = 403; int x_bl = 516; int x_or = 629; int y = 377; int x = 0; int num = 0; int w = 720; int h = 576; boolean hit = false; int i=0; int j=0; int pin = 11; color gruen = color(0, 255,0); color rot = color(255, 0,0); color gelb = color(255, 255,0); color blau = color(0, 0,255); color orange = color(255, 170,0); color fc = color(0,0,0); color blank = color(255,255,255); void setup(){ int w = 720; int h = 576; //int w = 320; //int h = 240; colorMode(HSB, 255); size(w,h); m = new JMyron(); m.start(720,576); m.findGlobs(1); println("Myron " + m.version()); //arduino setup arduino = new Arduino(this, Arduino.list()[1], 115200); arduino.pinMode(11, Arduino.OUTPUT); arduino.pinMode(12, Arduino.OUTPUT); arduino.pinMode(13, Arduino.OUTPUT); } void mousePressed(){ println(mouseX); println(mouseY); } void draw(){ m.trackColor(255,255,255,255); m.update(); int[] img = m.image(); //first draw the camera view onto the screen loadPixels(); for(int i=0;i<width*height;i++){ pixels[i] = img[i]; } updatePixels(); for(int j=0; j<=2; j++) { switch(j) { case 0: x = x_gr; fc = gruen; break; case 1: x = x_ro; fc = rot; break; case 2: x = x_ge; fc = gelb; break; } color cp = pixels[y*w+x]; float value = brightness(cp); //check if brightness value is above if (value >= 200) { hit =true; pin = pin + 1; arduino.digitalWrite(pin, Arduino.HIGH); arduino.digitalWrite(pin, Arduino.LOW); } noStroke(); fill(blank); if (hit) { fill(fc); hit = false; } rect(x, 0, 55, 55); rect(x_gr, y, 5, 5); rect(x_ro, y, 5, 5); rect(x_ge, y, 5, 5); rect(x_bl, y, 5, 5); rect(x_or, y, 5, 5); } } public void stop(){ m.stop(); super.stop(); }