diff --git a/.gitignore b/.gitignore index 85f269a..1ed9360 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ application.linux64 application.windows32 application.windows64 application.macosx + +ephimera/data/ diff --git a/arduino/arduino.ino b/arduino/arduino.ino index 889e843..7d4c5e0 100644 --- a/arduino/arduino.ino +++ b/arduino/arduino.ino @@ -1,4 +1,3 @@ - #include #include @@ -7,45 +6,54 @@ 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 + +int atomPins[] = {2,3,4,5,6,7,8,9}; +int currentValue = 0; +int values[] = {0,0,0,0,0,0,0,0,0}; +int cycle = 0; void setup() { Serial.begin(9600); + for(int i=0; i<8; i++) { + pinMode(atomPins[i], OUTPUT); + } + pwm.begin(); pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates delay(10); } + +void loop() { + if(Serial.available()){ + int incomingValue = Serial.read(); + + values[currentValue] = incomingValue; -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; + currentValue++; + if(currentValue > 8){ + currentValue = 0; } + cycle = 0; } -} - -void svuota(){ -} + while(cycle != 8) { + for(int i=0; i<8; i++) { + if(values[i]>0) { + values[i]--; + digitalWrite(atomPins[i], HIGH); + pwm.setPWM(i, 0, 400); + if(values[i]==0) { + digitalWrite(atomPins[i], LOW); + pwm.setPWM(i, 0, 100); + cycle++; + } + } + } + delay(100); + } +} diff --git a/ephimera/data/shot.gif b/ephimera/data/shot.gif deleted file mode 100644 index db27fad..0000000 Binary files a/ephimera/data/shot.gif and /dev/null differ diff --git a/ephimera/ephimera.pde b/ephimera/ephimera.pde index 36aaded..d974ae4 100644 --- a/ephimera/ephimera.pde +++ b/ephimera/ephimera.pde @@ -14,7 +14,7 @@ void setup() { size(640, 480, P2D); frameRate(10); colorMode(HSB, 100, 100, 100); - + String portName = Serial.list()[0]; port = new Serial(this, portName, 9600); @@ -26,11 +26,8 @@ void setup() { void draw() { ephPercentage(); - ephSerial(); } - - void keyPressed() { if (key == 'S' || key == 's') { video.stop(); diff --git a/ephimera/percentage.pde b/ephimera/percentage.pde index 02257fa..6d4059a 100644 --- a/ephimera/percentage.pde +++ b/ephimera/percentage.pde @@ -2,7 +2,10 @@ int cellSize = 20; int cols = videoWidth / cellSize; int rows = videoHeight / cellSize; int cellN = (cols)*(rows); -byte[] colorValues = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +int[] colorValues = {0, 0, 0, 0, 0, 0, 0, 0}; +byte[] colorByteValues = {0, 0, 0, 0, 0, 0, 0, 0}; +int colorsN = colorValues.length; +float colorsRange = float(100)/float(colorsN-2); void ephPercentage() { @@ -10,7 +13,7 @@ void ephPercentage() { video.read(); video.loadPixels(); - for(int i = 0; i 20 && briVal < 80) { - colorValues[int(hueVal/8.3)]++; + colorValues[constrain(int(hueVal/colorsRange),0,colorsN-3)]++; } else if(briVal <= 20) { - colorValues[12]++; - } else if(briVal >= 20) { - colorValues[13]++; + colorValues[colorsN-2]++; + } else if(briVal >= 80) { + colorValues[colorsN-1]++; } pushMatrix(); @@ -52,17 +55,14 @@ void ephPercentage() { } // Print colors percentage values - for(int i = 0; i