Random Question on how the loop works

I am writing my third program to work with some Hl1606 chips (rgb led controller) and I hacked up a old RF controller I had and have two seperate programs that work.

Now my question is I can't seem to integrate one into the other. The program that runs the leds works fine, but I basically cut and pasted my other program parts into the correct areas above the led control,

If the program is designed to move to the next type of led display after 128 pulses, does it also wait till then to read the digital pins? I can't seem to get it to read any pins when I have it in the LED program, but when I run my other program all the pins work properly.

Read this before posting a programming question

Your code?

The loop is very sequential. It implements one command at a time. If you tell it to do 128 pulses, then it will do them before it reads anything. The only way around this... as far as I know... is to imbed the digital reads in whatever code you are using to drive the pulsed. Like sticking it before a delay() command.

Nick, sorry I didn't post it, but didn't think it needed it to answer my simple question,

THank you RPCoyle, thats kinda what I was thinking when I was watching the serial monitor, be nice to be able to define loop 1 loop 2 loop 3 ect, although it would eat up most of the processor.

Thanks again Brandon

be nice to be able to define loop 1 loop 2 loop 3 ect

You can. They don't have to be called loopN(), though. Only the loop() function gets called over and over. In that function, though, you can call any other function, including ones that you write.

although it would eat up most of the processor.

Calling other functions takes minimally more time, and no more processing power, than inlining the code.

If your functions take up "most of the processor", inlining the code won't change that.

If you mean that you want to run several loop() instances simultaneously, forget it. The Arduino is not a multi-threaded device.

Ah, thx for the clarification, so to do a digital read while something else is occurring may be a bit difficult without putting some short delays with another digital read in, guessing that how it would need to be done

Thanks again guys Brandon

so to do a digital read while something else is occurring may be a bit difficult without putting some short delays

Doing a digital read (which is fast) while something else is occurring is not just difficult. It is impossible. Adding delays will NOT help. That's not even going in the right direction.

crazyone: THank you RPCoyle, thats kinda what I was thinking when I was watching the serial monitor, be nice to be able to define loop 1 loop 2 loop 3 ect, although it would eat up most of the processor.

The processor only (effectively) executes 1 instruction at a time. Whether you interleave code to give the appearance (to us slow humans) of multitasking or not, it only executes 1 instruction at a time.

Some instructions - like delay() occupy the processor for the whole time the instruction is active. That is why using millis() is often recommended. millis() requires more complex code because you have to check for the timeout, but while you are waiting for it to timeout yo can be doing other operations. You do need to be careful that those other operations don't tie up the processor or your timing won't be very accurate.

Multitasking/multithreading is just a fast processor being able to get a lot of work done in very short amounts of time. You still see your Windows/Linux box seem to slow down at times because some operation requires more processor time.

delay() is the arch nemesis of multi-tasking.

Learn Blink without delay. It's the right way to code.

crazyone: If the program is designed to move to the next type of led display after 128 pulses, does it also wait till then to read the digital pins? I can't seem to get it to read any pins when I have it in the LED program, but when I run my other program all the pins work properly.

A tutorial on doing multiple things:

http://www.gammon.com.au/blink