Two loops???

Hello,

Is there any way to run theses two loops at the same time….

while (true) { val = analogRead(potPin); // read the value from the sensor digitalWrite(ledPin, HIGH); // turn the ledPin on delay(val); // stop the program for some time digitalWrite(ledPin, LOW); // turn the ledPin off delay(val); // stop the program for some time }


while (true) {

val2 = analogRead(potPin2); // read the value from the sensor digitalWrite(ledPin2, HIGH); // turn the ledPin on delay(val2); // stop the program for some time digitalWrite(ledPin2, LOW); // turn the ledPin off delay(val);

}

Thanks, Drew Davis

No. But if you look at the blink without delay example, you'll get a clue to how to achieve what you want.

Hello,

I looked at the example you suggested but I still can't figure out how to get the lights to blink to different potentiometers.

I have some programing experience, but not with this language. If you could elaborate a little bit I would greatly appreciate it. Is there not a command to runs two tasks at the same time?

Thanks, Drew Davis

In the blink without delay example, there's a variable called "interval". Try setting the value of it using your potentiometer.

drewdavis: Hello,

I looked at the example you suggested but I still can't figure out how to get the lights to blink to different potentiometers.

I have some programing experience, but not with this language. If you could elaborate a little bit I would greatly appreciate it. Is there not a command to runs two tasks at the same time?

Thanks, Drew Davis

After a whole 15 minutes, you couldn't figure it out? It's going to take more effort than that.

I just thought there was some easy command.

For ex. when programing A VEX Robot you simply write StartTask(1);
StartTask( 2 ); etc.

Thanks,
Drew Davis

drewdavis: I just thought there was some easy command.

There isn't any such thing in the Arduino. Somebody did create a library that would let you define an action to be carried out after a delay or at regular intervals, but it's so easy to do yourself once you understand how 'blink without delay' works that I don't think it's necessary to use a library; you're only looking at a couple of lines of code for each separate thing you want to control. In any case I suggest that this is so simple to do that you should do it yourself first, even if you subsequently decide to use somebody else's solution later.

Some of these little mini task things are really easy to do in Bitlash. Here's the application you described:

// two blinkers on d13 and d12 controlled by pots on a1 and a2
function t1 { d13=!d13; snooze(a1); }
function t2 { d12=!d12; snooze(a2); }
function startup { pinmode(13,1); run t1; pinmode(12,1); run t2; }

-br

Update…

Thanks to all your help I was able to make it work using the blink without delay program!!!

Also, what is bit lash?

Thanks again, Drew Davis

Congratulations on solving the problem.

Bitlash is a language interpreter that runs on the Arduino. It implements a simple language that is similar to C, and many of the customary Arduino library functions are built in. You can use the Bitlash library from your sketch, and expose functions from your C code as Bitlash functions.

More at http://bitlash.net or you can go straight to the book: http://bitlash.net/bitlash-users-guide.pdf

-br