From cb761340a04e6725e67d37842791b44066fb7e75 Mon Sep 17 00:00:00 2001 From: Carmine De Rosa Date: Sun, 13 Oct 2019 10:26:06 +0200 Subject: [PATCH] fix bad git merge and add documentation --- README.md | 15 +++- arduino/arduino.ino | 97 ++++++++++++++++------ ephimera/ephimera.pde | 6 +- ephimera/frames.pde | 0 ephimera/history/shot_20190927_175024.gif | Bin ephimera/history/shot_20190927_175028.gif | Bin ephimera/percentage.pde | 0 ephimera/serial.pde | 1 + script/ephimera.sh | 0 9 files changed, 90 insertions(+), 29 deletions(-) mode change 100755 => 100644 ephimera/frames.pde mode change 100755 => 100644 ephimera/history/shot_20190927_175024.gif mode change 100755 => 100644 ephimera/history/shot_20190927_175028.gif mode change 100755 => 100644 ephimera/percentage.pde mode change 100755 => 100644 script/ephimera.sh diff --git a/README.md b/README.md index d813ce5..d96f0fc 100644 --- a/README.md +++ b/README.md @@ -1 +1,14 @@ -ephimera +## Ephimera + +### Keyboard commands + +``` +ESC - Exti from the program ans shutdown +``` +``` +U - Unload liquid from the pumps +``` +``` +1-8 - Load liquid in single pumps (from 1 to 8) +``` + diff --git a/arduino/arduino.ino b/arduino/arduino.ino index 52106b7..8be94ed 100644 --- a/arduino/arduino.ino +++ b/arduino/arduino.ino @@ -7,17 +7,23 @@ Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); #define SERVOMAX 390 // this is the 'maximum' pulse length count (out of 4096) #define TIMER 200 #define SERVODIVIDER 5 +#define STRIP 10 -const char HEADER = 'H'; +const char HEADER = 'H'; const char A_TAG = 'M'; const char B_TAG = 'X'; const char C_TAG = 'U'; +const char F_TAG = 'F'; + const int TOTAL_BYTES = 10 ; // the total bytes in a message int atomPins[] = {2,3,4,5,6,7,8,9}; int currentValue = 0; int values[] = {0,0,0,0,0,0,0,0}; + int cycle = 0; +boolean fadeDirection = 0; // 0 grow +byte fadeStatus = 0; void setup() { Serial.begin(9600); @@ -27,8 +33,8 @@ void setup() { pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN); } - pinMode(13, OUTPUT); - digitalWrite(13, HIGH); + pinMode(STRIP, OUTPUT); + fadeIn(); pwm.begin(); pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates @@ -57,44 +63,56 @@ void loop() { values[i] = 0; } - if(Serial.available() >= TOTAL_BYTES) { if( Serial.read() == HEADER) { char tag = Serial.read(); + + if(tag == F_TAG) { + fadeOut(); + } + if(tag == A_TAG || tag == B_TAG) { for(int i=0; i<8; i++) { values[i] = Serial.read(); } } - + + for(int i=0; i<8; i++) { + if(tag == A_TAG) { + pwm.setPWM(i, 0, SERVOMAX+50); + delay(100*SERVODIVIDER); + pwm.setPWM(i, 0, SERVOMAX-50); + delay(100*SERVODIVIDER); + } + pwm.setPWM(i, 0, SERVOMIN); + delay(values[i]*SERVODIVIDER); + pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN); + } + if(tag == C_TAG) { + for(int i=0; i<8; i++) { pwm.setPWM(i, 0, SERVOMAX+50); delay(100*SERVODIVIDER); pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN); } + + } else { for(int i=0; i<8; i++) { - if(tag == A_TAG) { - pwm.setPWM(i, 0, SERVOMAX+50); - delay(100*SERVODIVIDER); - pwm.setPWM(i, 0, SERVOMAX-50); - delay(100*SERVODIVIDER); - } - pwm.setPWM(i, 0, SERVOMIN); - delay(values[i]*SERVODIVIDER); - pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN); + Serial.print(values[i]); + Serial.print(" "); + if(values[i]>0) { + values[i]--; + digitalWrite(atomPins[i], HIGH); + if(values[i]==0) { + cycle++; + digitalWrite(atomPins[i], LOW); + } + } } - /* - for(int i=0; i<8; i++) { - pwm.setPWM(i, 0, SERVOMIN); - delay(values[i]*SERVODIVIDER); - pwm.setPWM(i, 0, ((SERVOMAX-SERVOMIN)/2)+SERVOMIN); - } - */ - if(tag == A_TAG) { while(cycle < 8) { cycle = 0; @@ -111,12 +129,43 @@ void loop() { } else { cycle++; } + + for(int f=0;f<4;f++){ + fadeGradient(); + delay(TIMER/(8*4)); + } } Serial.println(""); - delay(TIMER); } + + fadeIn(); } } } } -} \ No newline at end of file +} + +void fadeIn() { + for(int i=0; i<255; i++) { + analogWrite(STRIP, i); + delay(10); + } +} + +void fadeOut() { + for(int i=255; i>0; i--) { + analogWrite(STRIP, i); + delay(10); + } +} + +void fadeGradient() { + if(fadeDirection == 0) {fadeStatus++;} + if(fadeDirection == 1) {fadeStatus--;} + + if(fadeStatus == 0) {fadeDirection = 0;} + if(fadeStatus == 255) {fadeDirection = 1;} + + analogWrite(STRIP, fadeStatus); +} + diff --git a/ephimera/ephimera.pde b/ephimera/ephimera.pde index 2f9224b..bd57b53 100644 --- a/ephimera/ephimera.pde +++ b/ephimera/ephimera.pde @@ -43,6 +43,7 @@ void draw() { if (GPIO.digitalRead(4) == GPIO.LOW && takePicture == true){ takePicture = false; + sendMessage(F_TAG, colorByteValues); delay(4000); video.pause(); makePicture(); @@ -57,7 +58,6 @@ void draw() { } void keyPressed() { - if (key == 'S' || key == 's') { video.pause(); makePicture(); @@ -68,13 +68,11 @@ void keyPressed() { if (key == 'G' || key == 'g') { video.start(); } - if (key == 'U' || key == 'u') { sendMessage(C_TAG, colorByteValues); } - if (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8') { - for(int i = 0; i