Pages: [1]   Go Down
Author Topic: READING CODE SIMULTANEOUSLY?  (Read 814 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi
I am a beginner in this subjekt smiley-grin
Is it possible to run two parts of the code at the same time?
ex.
void setup()
{
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
}
  void loop()
  {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
  }
  void loop ()
  {
  digitalWrite(12, HIGH);
  delay(2000);
  digitalWrite(12, LOW);
  delay(2000);
  }

I know that I cant use void loop twice, but is it possible in some other way?
I hope you understand me  smiley-razz

grateful for answers
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want two LEDs to turn on at the same time, and off at the same time, do that.
Code:
void loop ()
{
  digitalWrite(12, HIGH);
  digitalWrite(13, HIGH);
  delay(2000);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
  delay(2000);
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you for reply

but if I want one of the LED blink with 1 sec and the other with 2 sec but start at the same time. Is it possible?
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.arduino.cc/playground/Code/TimedAction

Take a look at the 'The examples at once' which 'reads' three arduino examples at once.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks!
Thats what Im looking for.
But I have one question, when I copy the code and when I veryfi it it says "TimedAction does not name a type" and the row that is highlighted is

TimedAction blinkAction                 =       TimedAction(1000,blink);

what is the problem?
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you download the library? Refer to the download section.

Did you #include <TimedAction.h>  ?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

oh...sorry, missed it
starting to get late, my bad
Logged

Norway@Oslo
Offline Offline
Edison Member
*
Karma: 12
Posts: 2033
loveArduino(true);
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No worries smiley

Good luck!
Logged

Pages: [1]   Go Up
Jump to: