arduino uno water drop controller changes

Hi folks,
This is a great forum and I hope that I can find some help here.
I bought my first Arduino week ago and I have not had much sleep since. Its magic!
So as of today I have 5 (five) days programing experience and 5 sleepless night so don't brush me off if the question is to basic for you. I have been reading the last two nights on my problem, but I cant resolve it.
If you would like to help me and add some smarts to the code I am working on please do so.

I started (thank you RogerW) with the code from project guidance - Arduino Uno Water Drop Controller - Project Guidance - Arduino Forum
the original code was very close to what i needed and RogerW saved me many weeks :sweat_smile:
So I started modifying the code to fit better what I needed.
considering that i had to retype the posting 3 times as i last it by pressing the backpace on the keyboard while the focus was not on the posting, i decided to be very careful this time.
I attached the latest version of that I worked on and it compiles and runs OK except all of the actions in the code run in series
From reading for 2 nights about timings, interrupts and parallel operations, I figure i can use msTimer2 or some interrupts, but due to lack of experience, sleep or brain, I could not figure out way to do it so please do not send me to read more... Not now any way, maybe in few days...

here is what I'm doing now
I have variable that is hard coded to define the delay after which the camera will fire:
int cameraDelay=500;
I have created aditional 3 var
int cameraDelay1=(cameraDelay-pulseWidth0);
int cameraDelay2=(cameraDelay1-pulseSep0-pulseWidth1);
int cameraDelay3=(cameraDelay2-pulseSep1-pulseWidth2);
for each case of 1, 2 or 3 drops, I account for the delays introduced by drop sequence.
This is fine, but as I said earlier there is a fundamental problem with that approach - the camera can't fire before the drop sequence is executed - the cameraDelay can't be less then the sum of the drop sequence delays
int pulseWidth0 = 0; //Valve ON Time (Drop1 Size)
int pulseWidth1 = 0; //Valve ON Time (Drop2 Size)
int pulseWidth2 = 0; //Valve ON Time (Drop3 Size)
int pulseSep0 = 0; // Drop Seperation time (Time Between Drop1 & Drop2), valve off time
int pulseSep1 = 0; // Drop Seperation time (Time Between Drop2 & Drop3), valve off time

What I would ideally want is to start the camera delay timer after the first drop is initiated,
digitalWrite(valveControl,VLVON); //Valve ON
digitalWrite(dropsAway,dropsAwayON); //indicator LED on
///I need to start the timer delay countdown here///
after the timer countdown is completed, I would like to fire the camera in independent functio regardless where the drop sequence is.
something like
void cameraFire(){
digitalWrite(cameraShutter,cameraShutterON); //opens camera shutter
delay(50)
digitalWrite(cameraShutter,cameraShutterOFF); //closes camera shutter
}

It is probably very easy for most of you, so please help?

Thank you!

water_drop_controller_cam_out.ino (26.3 KB)

  //load our variables from EEPROM
  DropCount = EEPROM.read(0);
  pulseWidth0 = EEPROM.read(1);
  pulseSep0 = EEPROM.read(2);
  pulseWidth1 = EEPROM.read(3);
  pulseSep1 = EEPROM.read(4);
  pulseWidth2 = EEPROM.read(5);

We have no idea what values you have stored in EEPROM.

void outloop()

{

  int cameraDelay1=(cameraDelay-pulseWidth0);
  int cameraDelay2=(cameraDelay1-pulseSep0-pulseWidth1);
  int cameraDelay3=(cameraDelay2-pulseSep1-pulseWidth2);
{

Why is there a useless curly brace there?

if (DropCount == 1);
else if (DropCount == 4); 
else ; //exit routine

Crap, crap, and more crap.

If statements do NOT end in semicolons. They are followed by blocks (may be just one statement) of code to execute.

If there is nothing to do in the else condition, leave the else statement out.

    EEPROM.write(0,DropCount);                           // store variables for next startup
    EEPROM.write(1,pulseWidth0);
    EEPROM.write(2,pulseSep0);
    EEPROM.write(3,pulseWidth1);

Unconditionally writing to EEPROM is not a good idea. EEPROM has a limited (though high) number of write cycles.

Hi Paul,
Thanks for the reply.
From your reply I gather you maybe have experience in programming and you are good of critiquing.
Well, if I knew better how to write code, I would have done so! But I don't, and is know I have long way to go. You are probably right on all your comments. And the truth is I don't know better...
What you wrote is pointing out problems without giving solutions. As I mentioned in my first post I rather have someone show me how it's done rather than telling me I've done it wrong.

So can you provide some help and guidance instead or in addition to the critique?
Thanks again

So can you provide some help and guidance instead or in addition to the critique?

I could, if I had any idea that you were trying to do in each block I commented on.

Deleting the useless curly braces seems like something that you should be able to do, now that you know which one is useless. Finding the mate should be easy.

Telling us what IS in EEPROM shouldn't be that difficult.

The if statements could be a challenge.

Not unconditionally writing to EEPROM should be enough of a hint as to what you need to do.

Hi Paul,
I attach the entire file in my first post. As I said I started with code written by somebody else (again, thank you RogerW) and from what I understands he is writing in the EEPROM the values for pulseWidth0 1, 2 and pulseSep0, 1. In my opinion this is done in outloop()

EEPROM.write(1,pulseWidth0);
EEPROM.write(2,pulseSep0);
EEPROM.write(3,pulseWidth1);

I understand that the first time you run the code there will be a problem reading values from the EEPROM but after that is fine.
I fix the issue with the {} thank you.
So now back to my real problem:
How do the timer for the camera to run independent?
Please help if you can.

How do the timer for the camera to run independent?

Independent of what? When you release the water drops? Why would you want to do that?

What I would ideally want is to start the camera delay timer after the first drop is initiated,
digitalWrite(valveControl,VLVON); //Valve ON
digitalWrite(dropsAway,dropsAwayON); //indicator LED on
///I need to start the timer delay countdown here and wait for it, then///
void cameraFire(){
digitalWrite(cameraShutter,cameraShutterON); //opens camera shutter
delay(50)
digitalWrite(cameraShutter,cameraShutterOFF); //closes camera shutter
}
This way the camera will have the exact timing ever time I execute start sequence. If I change the timing of the drops I don't need to change the timing of the camera too to account for that.

What I would ideally want is to start the camera delay timer after the first drop is initiated,

I guess I might be missing something, so I'll try again. What is stopping you from doing that? If you need permission, consider it granted.

If I could, I would -with or without your permission. I obviously should not expect any constructive guidance from you.

If I could, I would

Fancy footwork, but I still don't understand why you can't. If you don't know how, be bold, and say that.

Hi Paul,
I was not hiding that...
I think I highlighted my geen-nes in the first post:

From reading for 2 nights about timings, interrupts and parallel operations, I figure i can use msTimer2 or some interrupts, but due to lack of experience, sleep or brain, I could not figure out way to do it so please do not send me to read more... Not now any way, maybe in few days...

you are correct! I have no clue how to do it. I was reading more as we speak, but i have not been successful yet...
Would you help me to see the light?