// ***** Processing code ***** // Send scaled value of the mouseX to serial port // -Assumes Atmega168 is expecting values between 1-10 // (Uncomment code re: camera if you have a webcam attached.) // ---------------------------------------------------------- import processing.video.*; Capture cam; import processing.serial.*; Serial myPort; // Create instance of serial port: int scaledOut; // Capture cam; void setup() { size(1000, 550); //----------------- Sorting the Serial connection ----------- println(Serial.list()); // Diagnostic: gives list of ports myPort = new Serial(this, Serial.list()[2], 9600); // Open connection to USB port at 9600 bps // cam = new Capture(this, 640, 480); // (Use 320 x 240 if 640x480 stutters.) //---------------- Ok for Serial, Now for the Camera -------- String[] cameras = Capture.list(); if (cameras == null) { println("Failed to retrieve the list of available cameras, will try the default..."); cam = new Capture(this, 640, 480); } if (cameras.length == 0) { println("There are no cameras available for capture."); exit(); } else { println("Available cameras:"); for (int i = 0; i < cameras.length; i++) { println(cameras[i]); } // The camera can be initialized directly using an element // from the array returned by list(): cam = new Capture(this, cameras[0]); // Or, the settings can be defined based on the text in the list //cam = new Capture(this, 640, 480, "Built-in iSight", 30); // Start capturing the images from the camera cam.start(); } //------------------- Now for the rest of setup --------------------------------- background(0); rectMode(CENTER); PFont fontA = loadFont("ArialMT-42.vlw"); // *** Create this with "Tools/Create Font..." textFont(fontA, 42); textAlign(CENTER); fill(220,200,20,90); // Set the fill color of the letters } void draw(){ scaledOut = (mouseX/99); text(scaledOut, 500, 530); myPort.write(scaledOut); // send scaled mouse x value background(0); if (cam.available() == true) { cam.read(); } image(cam, mouseX, 0); delay(50); // wait a twentieth of a second } |