Turning camera off / Start sailboat race machine

Hi guys,
I have very little to none experience if comes to programming Arduino and hope that one of you will help me with the program I have.
I'm building the start sailboat race machine and at this point I have the timer the way I like it but the camera doesn't turn off.
Can you make the change to the program so the camera will turn off one minute after the final horn and the program will go to stand by?
Thank you for you effort.

Timer_Camera.ino (4.33 KB)

I got no further than this before I stopped looking for problems

byte klick[1312];

It may not be causing your problem depending on which board you are using, but do you really need to use 1312 bytes of RAM like this, particularly as you seem to waste most of them because as far as I can see you never reference most of them anyway.

Thank you but this is definitely not a problem. I'm using OSEPP Uno R3 Plus.

Thank you but this is definitely not a problem.

Please explain why using 65% of the memory on a 328-based Arduino for one array is not a problem.

If you have a better way I'm all ears. I'm only interested in making it work so I can build the machine and go sailing.

You've also got

 while (true) {

What is this for? All you're doing is forcing perpetual loop within the loop function that would already loop for you.

The only thing this acheives is to prevent the arduino from processing it's Serial port for houskeeping.

Have you ever wondered why the loop function is called "loop"?

Braindeaf:
If you have a better way I'm all ears. I'm only interested in making it work so I can build the machine and go sailing.

Pin back your ears.
It looks to me as though you need to implement a state machine. It sounds scary but isn't.
Write down each of the states that you program can be in, such as waiting for a button to be pressed, waiting for time to elapse etc. Give each state a unique number and write down what event will cause the state to end and the state to move to.

In the program set a state variable to the initial state then use switch/case to execute the commands for each state. Something like this :

state = 0
start of loop()
  switch based on state
    case 0
      when the button becomes pressed
      make a beep
      set state to 1
      save start time of state 1
      break
      
    case 1  
      when 10 seconds has elapsed
      turn on the camera
      set state to 2
      break
      
    case 2
      when a boat passes the finish line
      turn off the camera
      set state to 0
      break
  end of switch
end of loop()

NOTE - this does NOT try to do what your program does but you should be able to see what is possible. Use millis() for timed events and when reading switches it is usually better to act when the switch becomes active rather than when it is active in order to prevent false readings.

Maybe look at the the Thread planning and implementing a program ?

It has many of the ingredients for your project.

...R

Ok then, like Spongebob said "TOMORROW FOR SURE"

Braindeaf:
Ok then, like Spongebob said "TOMORROW FOR SURE"

I haven't ever watched Spongebob so I don't understand.

...R

You should. It is the one of the best cartoons ever.
It means I will work on it tomorrow. However if I'm not going to work on it tomorrow then it is going to be a next day or a next day and so on.

Robin2:
I haven't ever watched Spongebob so I don't understand.

You're missing out :slight_smile:

You're missing out

No, I'm not.

I see that you are Winnie the pooh fan.
It's OK. Whatever makes you happy.

Braindeaf:
You should. It is the one of the best cartoons ever.
it means I will work on it tomorrow. However if I'm not going to work on it tomorrow then it is going to be a next day or a next day and so on.

Ahh. Not quite as urgent as manana.

...R

Today was "TOMORROW FOR SURE"
I made some changes and with 87% use of dynamic memory everything is working perfectly.
I removed parts of the horn sequence and parts of the program no longer needed. I added more klicks so the camera can record 1 minute past the final horn.
I understand that some of you focus on writing programs with minimum memory usage and this is great.
However, in my case simplicity of a program is more important. Simple program is more accessible and that in turn will allow more people to change starting timer with very little knowledge of programming.
I housed boards, camera, battery and camera power converter in the PELICAN box, but I'm not happy with that set up.
In a few days, I will move everything to a 3" PVC tube and I will seal both ends. The PVC tube will contain another sealed container that will house boards (I learned that salt water or ocean air are not good for the electronic components). The battery will be in a separate 3" PVC container and will be used as a power supply and as a ballast in the same time. Both PVC containers will be connected with a 2 or 3 feet of copper pipe, and a power cable will run inside of it. The starting line flag will be attached to the vertically floating tube and will be used as a wind vain that, at the same time, will keep the camera pointing at the other end of the starting line. Only the horn, the water proof toggle switch, and the camera lens will be exposed to the elements.
Yes, I have tons of fun building it.
Once I have it all running I will post it on YouTube.
For now, I've attached photos of my first prototype, so you know that I'm not "full of air" (line from SpongeBob).
Thank you all for your replies.

Timer_Camera_110914_forum.ino (2.76 KB)

Braindeaf:
I understand that some of you focus on writing programs with minimum memory usage and this is great.
However, in my case simplicity of a program is more important. Simple program is more accessible and that in turn will allow more people to change starting timer with very little knowledge of programming.

I agree 100% with making code accessible.

Your's is an interesting approach and I would certainly not dismiss it.

For the future you may wish to think about this derivative ...

You have only set about 20 values in the 1540 element array. You could get the same effect with an array with 20 elements each of which holds the step number and the value for that step.

Your "management" system could be the same but your memory usage would be very much less.

...R

Robin2 your advice makes perfect sense. The moment I will need more memory I will move things around and streamline the program.
Thank you for your help and being a good sport and most of all for your sense of humor.
Have a crack at SpongeBob. You will get a good idea what America and specifically Southern Cal is all about.

Finally I finished Race Starting Gizmo. I decided not to use a PVC pipe and instead used a pressure cooker as a float and a container. The machine was put to the test on Saturday and worked perfectly. The starting sequence worked flawlessly and video was very clear due to the fact that I installed the camera with the lens exposed to the element but sealed with o-ring. (no fogging) The flag is used as a wind vain to point the camera at the other end of the starting line. Arduino board with relays and a camera power supply is housed in a second water resistant plastic cup. Everything is running on 12v 1.3 Ah gel cell. This is it. Time to go boat racing. :sunglasses:

What is the exact goal of your project?

It looks like a "starting gun" for a yacht/sailboat race?