sorry but could you give me a example? I knew that was what i needed to do, but the only way i could workout how to do it was to repeat itself
If you could show me how to do this, it would solve a lot of problems in my project
sorry but could you give me a example? I knew that was what i needed to do, but the only way i could workout how to do it was to repeat itself
If you could show me how to do this, it would solve a lot of problems in my project
lowerstoford:
But, I'm stuck on a few things
press and hold fire buttons to start countdown - This is just not working, but if i pull the resistor from the button circuit, the countdown starts???
Safety checks, how do i keep checking that the safety rules are ok throughout the whole process?
Without a schematic, just shooting in the dark here, but do you fully understand using pullup resistors, and debouncing? There's quite a bit of code around on the forum for doing software debouncing, and also push-and-hold detection. Alas, the terms used are so common, that searching for that one really good post I remember isn't going to be fruitful. But maybe someone remembers a specific one they can find. ETA: See Interfacing with hardware, and do a find on the page for 'debounce'.
Also, your recursion in firebutton() is not going to work. The Arduino has limited stack space, and if you go long enough without pushing the button, you'll overflow the stack and then I don't know what happens, because on a computer with an OS, you'd get a stack overflow error, but there's no OS on the Arduino.
So do your continued checking of your fire buttons in a loop, decrementing and displaying your countdown as you go, and also do your safety checks in the same loop. Exit the loop (thus never executing the "fire" routine) if anything fails.
void CDtime()
{
//lcd.clear();
char keyPress;
lcd.print("Select Countdown");
lcd.setCursor (0,1);
lcd.print(" A:5 B:10 C:30 ");
do
{
keyPress = ourKeypad.getKey(); // Check the keypad
if(keyPress)
{
switch(keyPress)
{
case 'A':
cdt = 5;
break;
case 'B':
cdt = 10;
break;
case 'C':
cdt = 30;
break;
}
}
}
while(!keyPress);
}
do ... while
I was looking at that earlier, thank you for the example it now make sense
Now just have to get my head around millis
this is for tomorrow though as i must sleep now
Without a schematic, just shooting in the dark here, but do you fully understand using pullup resistors, and debouncing? There's quite a bit of code around on the forum for doing software debouncing, and also push-and-hold detection. Alas, the terms used are so common, that searching for that one really good post I remember isn't going to be fruitful. But maybe someone remembers a specific one they can find. ETA: See Interfacing with hardware, and do a find on the page for 'debounce'.
I used the button example from arduino learning
no debounce yet
no i don't really understand pullup resistors
here is a pic of the button circuit Green and yell switch black to arduino digital pin 50

but do you fully understand using pullup resistors
read the article
change the resistor to connect to 5v instead of ground and button works
thanks
now to look at de-bounce and push and hold
millis() is straight forward - its just a 32-bit, free-running counter that increments every millisecond.
Everytime you call it:
unsigned long currentTime;
unsigned long laterTime;
unsigned long duration = 100; //
now in void loop:
currentTime = millis();
you get a 32-bit number that is a snapshot of how many mS have elapsed since reset.
so get the time
currentTime = millis();
get it again later
laterTime = millis();
now compare:
if (laterTime - currentTime >= duration){ // enough time passed?
currentTime = laterTime; // re-set for next pass
do something}
otherwise,
let more time elapse, do other stuff, and next pass thru loop check the time again
laterTime will always be bigger that currentTime, and if you happen to run for 49+ days, when laterTime goes from 0xFFFFFFF0 to 0x00000010 say,
than 0x00000010 -0xFFFFFFE0 = 0x00000030 (bits above 32 are non-existent), so the math will give a correct result back.
Ok, I think I understand
So my task this evening is to change delay to millis and add debuging
I will let you know how I get on later
Thanks again for you help
what arduino are you using for this anyways the uno or the mega ADK? the uno wont be able to hold the code as its a lot of sketch but i have a few pointers as mentioned by a rather smart 17 year-old girl i know, she says first you need two mega2560/ mega ADK boards she says do not rely on radio telemetry for a launch control system that is asking for serious trouble she says it is an absolute must that all telemetry and control link between the two units be done using I2C or serial data-link over a shielded cable with locking type terminations at the ends. she is also wondering just what sort of motors the rockets are using. she says as a minimum she recommends this system have three control cables for size d and lower motors use cable 1 with a length of 25 ft for size e through g use cable 2 with a length of 50 ft for motors h or higher use cable 3 with a length of 100ft. she says replace the two button launch safety with a spring return dead man switch that must be held down at all times or the system will disable all outputs and lock them out and report an error. the lockout safety should require a code to reset this is to prevent simply resetting by removal of power. ive consulted with some people i know who work in the pyrotechnic industry and they second this recommendation.
Thanks for the info
I am using 2 mega 2560
Radio link did concern me, I would prefer cables
The radio link was going to come later anyway so I will forget that
For the link cable I am going to use CAT 6 with 8-pin locking DIN plugs/sockets
I have researched I2C and it doesn't look like it will work over the distances I require so I was going to use serial
The firing cables are 240v 13A mains flex
We will be firing A, B, C, D and E BP motors to start with and hope to fire up to I impulse if we ever get and reloads into the UK
I will look into the fire buttons/dead man but these are recessed push to make buttons so if you let got the count down will be aborted I think this is very safe, but maybe you could tell me in more detail why not
Thank you and your friend for the advice and anymore would be great
Lock out reset code would be great
Can't anyone tell me how to use my keypad to capture this as I have only got it working with one button press at the moment
I would like to change to countdown time select to have a manual input as well so you can select 2:30 for example but don't quite now how
And my son want to enter a code on power up for security so this would help implement this as well
I cant add much knowledge to the project, but well done its looking great!
For safety, wireless links should not be used. With a wired link, when you are adjusting the igniter near the pad, you absolutely know no one is near the launch button.
Not so with wireless; it's inappropriate in this design. Skip this forever for safety, not simplicity reasons.
Debounce! If your launch button is SPDT (single pole double throw), use an extra digital input pin and have perfect easy debounce.
You read both pins. One pin sets state On; the other pin sets state Off. Heavy bouncing will not change the state, only a contact of the other pin will.
Keypad is probably a matrix keypad. There is a library. Read this:
Arduino Playground - KeypadTutorial
Get each subsection working separately and perfectly first. Just the keypad. Just the launch button. Just the lcd screen. Just the ignitors.
Skip the separate power to relays. If you don't enable launch, you don't enable launch.
You''re a great Dad! Involve your son in the design, breadboarding, and/or test of each in 4. above.
Cool project. You're a great dad.
As long as you devise a robust enough protocol, I'd expect wireless to be safe enough. Come to that, you should consider the same thing even if you stick with wired.
I would just like to say a big thank you to everyone, for all the help, advice, suggestions and words of encouragement.
My work load is massive at the moment so I don't get to spend as much time as I would like on this project, but I'm hoping to get a few hours this evening to work on this
I will post some updates as soon as I can and I'm sure I will be back here asking more and more questions
Thanks again
Back again!
I have been trying for hours and hours now and I cant get a countdown timer to work using millis
please somebody help me this is causing major problems
All I want it to do is countdown from a varible that is selected earier
Beep every second
then run the fire function
Just cant see how
If anyone can help me I would be most greatfull
void CountDown2()
{
ElapsedTime = StartTime; //currentTime at this point is the current time from the previous iteration, this should now be pastTime
StartTime = millis(); //currentTime is now the current time (again).
unsigned long timePassed = StartTime - ElapsedTime; //this is roll-over proof, if currentTime is small, and pastTime large, the result rolls over to a small positive value, the time that has passed
do
{
shortBeep();
// ElapsedTime = millis();
}
while
(timePassed <= 5000);
fire();
} // end CountDown
//Timers End
if anyone can help right now let me know or I will give up tonight and try again tomorrow
it 1:45am and I should be in bed, but i really want to get this stupid thing working!
Tired ![]()
Let me see if I can help you with timer. As I read it, you just want to capture seconds.
unsigned long startTime = 0, currentTime = 0, seconds = 0;
void setup(){
startTime = millis();
}
void loop(){
currentTime = currentTime + ( millis()-startTime );
if ( currentTime == 1000 )
{
seconds = seconds + 1; // seconds holds the real seconds elapsed. You can use this wherever you want.
currentTime = 0; // reset it to 0 so counter can begin again.
}
} // end LOOP
I have not compiled or tested this but what you want to do is CAPTURE the startTime right before entering the loop. This will be the base time. Then in the loop you want to use millis() to get the current time and then subtract it from startTime to get the real elapsed time. Then, currentTime is a counter so it will just increment and when it hits 1000 milliseconds (1 seconds), increment the seconds variable and reset the currentTime so it can just keep repeating.
Next, anywhere in the loop you can do statements like:
if ( seconds == 10 ) // 10 seconds have passed
{
// do something like fire or launch missile
}
I hope this makes sense, good luck!
Here's a quick countdown timer, but bear in mind there's no stopping it once it starts. For safety, you'd need to add code to stop the countdown too.
byte countdown_time_seconds = 10;
byte countdown_time_remaining;
void setup() {
Serial.begin(9600);
Serial.println("Counting down...");
}
void loop() {
for (countdown_time_remaining = countdown_time_seconds; countdown_time_remaining >= 0; countdown_time_remaining--) {
//keep looping until we get to zero.
Serial.print("Will fire in: ");
Serial.println((int)countdown_time_remaining);
delay(1000);
}
Serial.print("Firing!");
}
[Edit] MushfiqSarker beat me to it!