Browse Source

add processing/arduino serial communication

develop
Carmine De Rosa 6 years ago
parent
commit
e027883d97
  1. 51
      arduino/arduino.ino
  2. BIN
      ephimera/data/shot.gif
  3. 27
      ephimera/ephimera.pde
  4. 14
      ephimera/frames.pde
  5. BIN
      ephimera/history/shot_20190927_175024.gif
  6. BIN
      ephimera/history/shot_20190927_175028.gif
  7. 2
      ephimera/percentage.pde
  8. 4
      ephimera/serial.pde

51
arduino/arduino.ino

@ -0,0 +1,51 @@
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
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(){
}

BIN
ephimera/data/shot.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

27
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();
}
}

14
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");
}

BIN
ephimera/history/shot_20190927_175024.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
ephimera/history/shot_20190927_175028.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

2
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() {

4
ephimera/serial.pde

@ -0,0 +1,4 @@
void ephSerial() {
port.write(colorValues);
}
Loading…
Cancel
Save