Can I run a part of a code once then continue onto the rest

Hi

I have a program that controls from ntc thermistors. Led lights and fans.

I was thinking I'd like to make a small demo, self test before it actually starts reading from my sensor.

I was thinking, from turn on.

  1. Cycle through all 6 LEDs in red
  2. Cycles through all 6 LEDs in blue
  3. Turn on all LEDs in red
  4. From red fade to blue over 5 seconds
  5. Start the fans, and slowly ramp them up to full speed.
    I would imagine all of this to complete is say 20 seconds
    Such as a demo...

Then assign the lights and fans to the sensors.

Can anyone tell me if this is possible

If it's possible I will start to look for some demos..

Thanks
Shaun

If I understand what you want it's just what setup() is for. It runs something once on startup and then when it's finished carries on to run the main loop() repeatedly.

Steve

toxsickcity:
Or do I need words to end a demo and start the next?

What do you mean by "start the next"?
Do you want to start the same program again? or do you want to run a different program?

Also, I'm not sure if the comment about the role of setup() in Reply #1 is actually dealing with your problem - it may be, or it may not.

Have a look at how the code in Planning and Implementing a Program is organized into functions.

If you organize your program like that you can call the functions in whatever order you want to.

...R

Many thanks for the reply, the link makes sense

In general, things that only need to get done once can be done in setup().

However, it is usual for someone with these requirements to come back after a couple of days and ask "Having to power-cycle this thing to see the demo again is a drag, it there some way to reset the sketch?"

The answer I give to that soon-to-be-coming question is "No. You do not 'reset the sketch'. You write a sketch which, as part of its normal operation, has a way to run the code that you want to be run when some event occurs."

That is - I suggest that you do not do this stuff in your setup(). I suggest that you crate a 'demo' function and call it from your setup. Then, at a later stage when you get jack of power cycling the sketch to see the blinkenlights, wire in a 'demo' button on a pin and put a call to that function somewhere in your loop() as appropriate.

It's how I want it to work.. it is to show that all LEDs are functional and that the fans can blow at full speed once a power cycle..
This will provide few functions for my project... clean dust from blades and pushing dust from the box. Seeing the full speed of the fan in action
The LEDs is more or less a demo to look cool and to show all LEDs work in all sections..

I won't be asking for a reset code or anything not that is possible as you state in last comment.

Thanks

I won't be asking for a reset code

Then putting the code or calls to functions to do what you want in setup() is the perfect solution