/* Projected Pixel Portrait Camera by Niklas Roy / 2018 Published under a "do whatever you want with this code but don't blame me if it doesn't work" - license Programmed in Processing 3.3.4 Arduino is connected with Firmata library uploaded to it A "start"-button is connected to the Arduino's Analog Pin 5 An LDR is connected via a voltage divider to the Arduino's Analog Pin 0 A beamer is connected to the computer and extends the computer's desktop to the right side */ import arb.soundcipher.*; import processing.serial.*; import cc.arduino.*; int[][] pixel = new int[100][100]; int xscan=0; // scanning position int yscan=0; int run=0; // state machine counter int counter=0; // loop counter int min=1024; // minimal brightness int max=0; // maximum brightness int resolution =50; // image resolution float pixelsize; float imgsize; int colorcycle=0; SoundCipher sc = new SoundCipher(this); Arduino arduino; void setup() { println(Arduino.list()); arduino = new Arduino(this, Arduino.list()[5], 57600); //size(1920, 1080); fullScreen(P2D, SPAN); frameRate(30); //fullScreen(); textSize(14); sc.tempo(60); sc.instrument(10); background(0); noCursor(); // ------------------------------------------------------------- calculate pixel size and image size pixelsize=1000.0/resolution; imgsize=resolution*pixelsize; } void draw() { counter++; fill(0); noStroke(); rect(1920, 0, 1920, 1080); // draw black backround on beamer noStroke(); colorMode(HSB, 100); // colored background fill(colorcycle%100, 100, 100); rect(0, 0, 1920, 1080); colorMode(RGB,255); if (run==0) { int button=arduino.analogRead(5); if (button<500 && counter>40) { // if button is pushed: run! [=reset and start scanning] run=1; min=1024; max=0; for (int x=0; x<50; x++) { for (int y=0; y<50; y++) { pixel[x][y]=0; } } sc.playNote(66, 100, 1); } } else { colorcycle++; // ------------------------------------------------------------- scan image xscan++; if (xscan>resolution-.001) { // end of line xscan=0; yscan++; if (yscanresolution-.001) { // end of image xscan=0; yscan=0; sc.playNote(106, 70, 2); run=2; } fill(255); rect(xscan*pixelsize+460+1920, yscan*pixelsize+40, pixelsize, pixelsize); // draw scanpixel int sample=arduino.analogRead(0); // sample brightness pixel[xscan][yscan]=sample; if (samplemax) { max=sample; } } // ------------------------------------------------------------- draw image int xx=0; int yy=0; for (float y=0; y