Go Down

Topic: help with visual countdown timer (Read 68 times) previous topic - next topic

hashtagbenghazi

Mar 15, 2016, 10:25 am Last Edit: Mar 19, 2016, 05:12 am by hashtagbenghazi Reason: formerly reinforced that old stereotype about guys never reading instructions
i'm attempting to build a countdown timer consisting of 7 LEDs.

i haven't changed the delay times to 5 minutes yet but the idea is that each 5 minutes one LED turns off, then the final LED blinks for 5 minutes before the program ends.

my final LED blinks on and off twice then the program restarts - can anyone give me some suggestions to help me reach my goal (non-stop blinking of final LED for 5 minutes then the ending of the program)?

thanks in advance, code below

p.s. i'm very new so i'm kind of shooting in the dark in this code, all help appreciated
the 'repeatCounter' is my attempt to get the LED to keep blinking haha

Code: [Select]
void setup() {


  pinMode (2, OUTPUT); //begin
  pinMode (3, OUTPUT);
  pinMode (4, OUTPUT);
  pinMode (5, OUTPUT);
  pinMode (6, OUTPUT);
  pinMode (7, OUTPUT);
  pinMode (8, OUTPUT); //overtime

}

void loop() {

  int ledNumber = 2;
  digitalWrite (2, HIGH);
  digitalWrite (3, HIGH);
  digitalWrite (4, HIGH);
  digitalWrite (5, HIGH);
  digitalWrite (6, HIGH);
  digitalWrite (7, HIGH);
  delay (1000);

  digitalWrite (ledNumber, LOW);
  delay (1000);

  digitalWrite (ledNumber + 1, LOW);
  delay (1000);

  digitalWrite (ledNumber + 2, LOW);
  delay (1000);

  digitalWrite (ledNumber + 3, LOW);
  delay (1000);

  digitalWrite (ledNumber + 4, LOW);
  delay (1000);

  digitalWrite (ledNumber + 5, LOW);
  delay (1000);

  int (ledNumber = ledNumber + 6);
  int repeatCounter = 1;

  if (ledNumber > 7) digitalWrite (8, HIGH); ////blink red LED
  delay (150);
  digitalWrite (8, LOW);
  delay (150);
  repeatCounter + 1;

  if (repeatCounter < 300) digitalWrite (8, HIGH); ////blink red LED
  delay (150);
  digitalWrite (8, LOW);
  delay (150);
 


}

septillion

Fist, welcome!

Second, you naughty boy, you didn't read the "How to use the forum";) Please go back and edit your post and add code tags (</> in the menu) around the code.

The about the code.

Variable names for pins are usually easier to remember ;)

Indent you code after each { to make it readable.

And of course it will only blink once. You're idea of counting the number of blinks is good, but then you have to loop over it ;) Now the only loop is loop which is restarting the whole problem.

And if you really want to whole program to run just once, place everything inside setup.
Use fricking code tags!!!!
I want x => I would like x
I need help => I would like help
Need fast => Go and pay someone to do the job...

aarg

This line does nothing:
Code: [Select]
repeatCounter+1;
What did you want it to do?
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

lastchancename

...and please lose the 'delay()' calls.

Set up a variable to keep track of the time, and make changes when that passes milestone times.

Using this method will allow you to check and perform other stuff like testing a button (e.g. to cancel the countdown) halfway through a 'delay' period.

PaulS

Code: [Select]
int (ledNumber=ledNumber+6);
Why are there parentheses here? You are assigning a new value to an int, and then casting the resulting value to an int. That's pretty much useless, wouldn't you agree?


hashtagbenghazi

thanks for the constructive criticism guys, i'll do some more reading and get back

i'll also have a proper look at the posting rules (woops) - cheers for the warm welcome septillion

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy