diff --git a/arduino/arduino.ino b/arduino/arduino.ino new file mode 100644 index 0000000..889e843 --- /dev/null +++ b/arduino/arduino.ino @@ -0,0 +1,51 @@ + +#include +#include + +Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); + +#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096) +#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096) + +String inputString = ""; // a String to hold incoming data +boolean stringComplete = false; // whether the string is complete + +void setup() { + Serial.begin(9600); + + pwm.begin(); + pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates + + delay(10); +} + + +void loop() { + // print the string when a newline arrives: + if (stringComplete) { + Serial.println(inputString); + // clear the string: + inputString = ""; + stringComplete = false; + } +} + +void serialEvent() { + while (Serial.available()) { + // get the new byte: + char inChar = (char)Serial.read(); + // add it to the inputString: + inputString += inChar; + // if the incoming character is a newline, set a flag so the main loop can + // do something about it: + if (inChar == '\n') { + stringComplete = true; + } + } +} + +void svuota(){ + +} + + diff --git a/ephimera/data/shot.gif b/ephimera/data/shot.gif new file mode 100644 index 0000000..db27fad Binary files /dev/null and b/ephimera/data/shot.gif differ diff --git a/ephimera/ephimera.pde b/ephimera/ephimera.pde index 11870af..36aaded 100644 --- a/ephimera/ephimera.pde +++ b/ephimera/ephimera.pde @@ -1,16 +1,22 @@ +import processing.io.*; import processing.serial.*; import processing.video.*; +import processing.serial.*; +Serial port; Capture video; +PImage img; int videoWidth = 640; int videoHeight = 480; void setup() { - size(640, 480); + size(640, 480, P2D); frameRate(10); colorMode(HSB, 100, 100, 100); - + + String portName = Serial.list()[0]; + port = new Serial(this, portName, 9600); video = new Capture(this, width, height); video.start(); @@ -20,4 +26,21 @@ void setup() { void draw() { ephPercentage(); + ephSerial(); +} + + + +void keyPressed() { + if (key == 'S' || key == 's') { + video.stop(); + printArray(colorValues); + makePicture(); + } + if (key == 'B' || key == 'b') { + backupFrame(); + } + if (key == 'G' || key == 'g') { + video.start(); + } } diff --git a/ephimera/frames.pde b/ephimera/frames.pde new file mode 100644 index 0000000..0ba497e --- /dev/null +++ b/ephimera/frames.pde @@ -0,0 +1,14 @@ +void makePicture() { + saveFrame("data/shot.gif"); + img = loadImage("shot.gif"); + ephSerial(); +} + +void backupFrame() { + // save picture with results for backup + saveFrame("history/shot_" + + nf(year(), 4) + nf(month(), 2) + nf(day(), 2) + "_" + + nf(hour(), 2) + nf(minute(), 2) + nf(second(), 2) + + ".gif"); + println("color count image saved"); +} diff --git a/ephimera/history/shot_20190927_175024.gif b/ephimera/history/shot_20190927_175024.gif new file mode 100644 index 0000000..db5400c Binary files /dev/null and b/ephimera/history/shot_20190927_175024.gif differ diff --git a/ephimera/history/shot_20190927_175028.gif b/ephimera/history/shot_20190927_175028.gif new file mode 100644 index 0000000..e2b29b3 Binary files /dev/null and b/ephimera/history/shot_20190927_175028.gif differ diff --git a/ephimera/percentage.pde b/ephimera/percentage.pde index aff2290..02257fa 100644 --- a/ephimera/percentage.pde +++ b/ephimera/percentage.pde @@ -2,7 +2,7 @@ int cellSize = 20; int cols = videoWidth / cellSize; int rows = videoHeight / cellSize; int cellN = (cols)*(rows); -int[] colorValues = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +byte[] colorValues = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; void ephPercentage() { diff --git a/ephimera/serial.pde b/ephimera/serial.pde new file mode 100644 index 0000000..9b43998 --- /dev/null +++ b/ephimera/serial.pde @@ -0,0 +1,4 @@ + +void ephSerial() { + port.write(colorValues); +}