NEED HELP ASAP! NEW TO ARDUINO!

I have a program I made that works. However, I want to put the entire program in a loop so that the entire program starts all over again and keeps going. Are there any commands or anything that can do that?? Thanks in advance! P.S. I'm using XBee wireless communication if that makes any difference.

I have a program I made that works.

Well done you. Where is it?

Please use better titles. Everyone who comes on this site "needs help asap" and most of them are also "new to arduino" - please include something specific in your title. I have no idea what the title should be for this thread though, because you give us no clue about what problem you have encountered.

Were you just introducing yourself? HI :)

Don't forget to use code tags.

http://forum.arduino.cc/index.php/topic,148850.msg1118324.html#post_codetags

jengo51: I have a program I made that works. However, I want to put the entire program in a loop so that the entire program starts all over again and keeps going. Are there any commands or anything that can do that?? Thanks in advance! P.S. I'm using XBee wireless communication if that makes any difference.

Three cheers for you! I wish I had a program I made that works.

Now go and READ THE STICKIES (yes, I can shout too) at the TOP of THIS FORUM and try asking your question PROPERLY.

What happened to the code tags?

Just take a look at the (oh, surprise surprise) BlinkWithoutDelay example sketch - and just slow it down a little...

Actually wait... he did post a question that we can actually answer... here goes...

jengo51: Are there any commands or anything that can do that??

YES. There are some commands and things that can do that.

The sketch already loops. You're just not writing the sketch in the right way.

You guys are too much sometimes.

If you want to ignore the transmitter for a minute, you can put your delay at the end of the loop code you have now: Replace: while (DATA == '1') //If button is pressed { digitalWrite(reminder, LOW); //Then the red LED should turn off forever }

with digitalWrite(reminder, LOW); //Then the red LED should turn off forever delay(60000); //timer waits for 1 minute

It is part of "loop" so after the delay it goes back to if (Serial.available() ...

You seem determined not to make the most of this free advice. You are asked to post the code properly and you do not. That is showing great discurtsy to everyone here.

Next you change the code and again do not post all of it.

Finally you ignore what advice you are given and keep asking the same question.

jengo51:
Really? Interesting observation…I mean when I upload it, it works, but how can I write it differently so the entire sketch loop itself again from the 60 second delay?

This is kind of a meaningless question “how to make it loop again” - because the loop function already runs over and over again, forever. It’s already looping. You just need to make it watch what time it is, so you can respond to events based on time. You could use the delay function to wait your 60 seconds, and then just let the loop end, it will run again, that’s the whole point.

However, that’s not really how we do Arduino stuff. The delay function causes all processing to stop - so you can’t detect a button press during that time for example. You need to restructure this program so the loop runs quickly with no delays. I made a video that explains why we need to do this and how to think it through. I really didn’t think I would be posting this so often… but here you go…

Tell me… have you actually looked at any of the material we have told you to look at?

Have you looked at the BlinkWithoutDelay example?
Have you watched the video?

Or are you just expecting us to do the work for you and give you some finished code so you never learn how to do things for yourself?

So I'm just confused; that's all.

No you are not you are trying to provoke. Put in a bit of effort please.

How can DATA ever change in that while loop? Once in you are stuck forever.

What are you trying to do with this code it seems to have little practical application.

BEFORE you post anything again read this link:- http://forum.arduino.cc/index.php?topic=97455.0

This is an infinite loop, do you see why?

while (DATA == '1')  {
  digitalWrite(reminder, LOW);   //Then the red LED should turn off forever
  delay(60000);   //timer waits for 1 minute
}

You still don't have much of a grasp of how the code relates to reality, do you?

Give up writing code for the time being. Instead, write what you want it to do in plain english, breaking it down into smaller and smaller steps.

jengo51: I watched the video (the one about the blinking) it helped me understand what's wrong. So, thank you to the user who posted that for me. So, since I put it in a while loop it will last forever. Is it allowed by Arduino for me to put the 60 second delay after the while loop? I mean outside of the while loop after its brackets are closed?

One thing at a time...

Look at your loop I posted above. Let's figure out why it will run forever. When that loop begins, what does it do? How can it start? When DATA is 1, right? Otherwise the loop doesn't run, right? So the question is, what keeps the loop running or causes it to end? In your code, is there anything that could possibly cause the loop to end?

Only consider the while loop for now. I'll walk you through this. It isn't how we normally do things here but I will hold your hand for a bit till you get going, ok?

Is it allowed by Arduino for me to put the 60 second delay after the while loop? I mean outside of the while loop after its brackets are closed?

Sure you can put the delay there. The only snag is that the processor will never execute that delay because it is stuck in the while loop. This is because there is nothing in the loop that can ever change the value of the DATA variable, so once in this loop you are stuck forever.

jengo51:

jasmine2501:

jengo51: I watched the video (the one about the blinking) it helped me understand what's wrong. So, thank you to the user who posted that for me. So, since I put it in a while loop it will last forever. Is it allowed by Arduino for me to put the 60 second delay after the while loop? I mean outside of the while loop after its brackets are closed?

One thing at a time...

Look at your loop I posted above. Let's figure out why it will run forever. When that loop begins, what does it do? How can it start? When DATA is 1, right? Otherwise the loop doesn't run, right? So the question is, what keeps the loop running or causes it to end? In your code, is there anything that could possibly cause the loop to end?

Only consider the while loop for now. I'll walk you through this. It isn't how we normally do things here but I will hold your hand for a bit till you get going, ok?

When DATA is 1 the while loop begins and makes reminder low or "off." In my code at the moment, there isn't anything that could make it end; so, I need to find something that could make it end, and start over. To make it end, should I/or can I possibly put in a chain of reactions for the while loop?

You need to keep checking the button and update the DATA variable somehow during the loop.

These are the basic parts of all loops in almost all languages... if you forget one of these parts, your loop will either fail to run or run forever.

  1. A loop control variable - in your case it's DATA, in many "for" loops it's "i"
  2. A loop control condition - in your case it's "DATA == 1" and if that condition is true, the loop "loops"
  3. A loop code body - that's the code "inside" your loop
  4. In the loop code body, you must update the loop control variable.

BTW - I can see from the timing of your posts that you didn't watch the video, then go build a breadboard and set up some code and try out what you just learned. You won't learn anything if you don't do that.

Have you purchased an Arduino starter kit and done all the experiments? I got one yesterday and it's freekin awesome! I'm going to do all the little experiments in the thing, even though I've been programming and building electronics for 30 years. If a person with my experience feels the need to do the little experiments in the starter kit, shouldn't you? (I think you're jumping in too fast)

I put up a review last night (videos are my thing) - this little starter kit is really cool. I built the first two experiments already, but I'm not continuing there... the code for the second experiment isn't right. It's more like your code, not like the code I showed in the video - so I'm leaving that breadboard set up until I fix the example code, because I know then I'll be able to make the 'experiment 2' LEDs work with a button and change their patterns. You have to do that kind of thing if you want to learn. Don't just do the example - change it, play with it. If a person like me can have that much fun playing with experiment number two in the starter kit... well, it's a pretty good experience is all I'm saying.

http://www.youtube.com/watch?v=pf4qosqpv3A

This is a very confusing thread. has the OP deleted all his posts?

...R