Neeeewbie might be over his head.

Hey everyone! Title says it all. I am simply trying to have 4 different sets of leds (2 leds per set) doing 4 different tasks. I am having a very hard time understanding how to do this. I can make the leds flash with no problem "digitalWrite(led2,High); etc". I feel I am over my head because I have no prior experience writing code. I work on cars- enough said. I almost need someone to write a sample code I can easly follow. Thank you ahead of time for the help I really need!!

Ok. Can you summarize what each of the four tasks is, and what each intends to communicate with its associated led?

Have you tried to write some code for the tasks yet? If you have, even if it's buggy it'll help us to understand (maybe) how you're approaching the solution - and even if it doesn't, it'll provide starting points for discussion with those who might choose to help.

Thank you for the reply. I've tried differnet methods through here and youtube clips. I couldnt get any of them to work so I deleted them.

The leds:

1 set: "led1,HIGH" "led2,LOW" delay(300) "led1,LOW" "led2,HIGH" delay(300)

2nd set: "led3,HIGH" "led4,HIGH" delay(100) "led3,LOW" "led4,LOW" delay(100)

3rd set: about the same as 1st set. I want to play with the timing of those. Maybe a delay of 100-150

4rth set: I would like those to stay on with no blink.

My project may seem silly, but Im into r/c cars/trucks and i want to add flashing lights similar to a police car. The r/c car Im installing it on is extremely fast and want it noticed. It will have 4, 5mm leds on the roof and 6, 3mm leds on the front. The first set will be "wig-wags". the 2nd set just flashing yellow lights. The 4rth set will be headlights. The 3rd set will have 2 blue leds and 2 red leds. Both blue will flash together and both red will flash together.

I thought the arduino would help me with this project, but I cant figure out the code. Ive looked on this forum, google, and youtube. Any help will BE appreciative!

You're half way there, the first example would look like this.

const int led1 = 10;  // define some pin numbers
const int led2 = 11;

digitalWrite (led1,HIGH);
digitalWrite (led2,LOW);
delay(300);
digitalWrite (led1,LOW);
digitalWrite (led2,HIGH);
delay(300);

then to select the 4 sequences

int seq = 2;  // get value from somewhere

switch (seq) {

    case 1:
        // sequence code here
        break;

    case 2:
        // sequence code here
        break;

    case 3:
        // sequence code here
        break;

    case 4:
        // sequence code here
        break;
}

Rob

Graynomad beat me to it (I'm a slow typist), but I'll post what I roughed out anyway. You'll need to replace question marks with appropriate numbers, but I don't think you'll have difficulty getting started.

#define LED11 ?
#define LED12 ?
#define LED21 ?
#define LED22 ?
#define LED31 ?
#define LED32 ?
#define LED33 ?
#define LED34 ?
#define LED41 ?
#define LED42 ?

#define T1 300
#define T2 100
#define T3 ?

unsigned long cur,prv1=0,prv2=0,prv3=0;
int s1=0,s2=0,s3=0;

void setup(void)
{  pinMode(LED11,OUTPUT); /* 1st set (wig-wag) */
   pinMode(LED12,OUTPUT);

   pinMode(LED21,OUTPUT); /* 2nd set (flashing yellow) */
   pinMode(LED22,OUTPUT);

   pinMode(LED31,OUTPUT); /* 3rd set (2 x blue,red) */
   pinMode(LED32,OUTPUT);
   pinMode(LED33,OUTPUT);
   pinMode(LED34,OUTPUT);

   pinMode(LED41,OUTPUT); /* 4th set (headlights) */
   pinMode(LED42,OUTPUT);

   digitalWrite(LED41,HIGH); /* Turn on headlights */
   digitalWrite(LED42,HIGH);
}
void loop(void)
{  cur = millis();
   if (cur - prv1 > T1) /* Set 1 - wig-wag */
   {  prv1 = cur;
      s1 = !s1;
      digitalWrite(LED11,s1);
      digitalWrite(LED12,!s1);
   }
   if (cur - prv2 > T2) /* Set 2 - flash together */
   {  prv2 = cur;
      s2 = !s2;
      digitalWrite(LED21,s2);
      digitalWrite(LED22,s2);
   }
   if (cur - prv3 > T3) /* Set 3 - (TBD) */
   {  prv3 = cur;
      s3 = !s3;
      /* Whatever you want set 3 to do */
   }
}

Thank You graynomad and Morris Dovey! I will try these out later this afternoon after work.

ok this is what i have so far and i get an error on this part (
pinMode(led22,OUTPUT); /* first set (wig-wag) */). It says "expected primary-expression before ‘,’ token. I still dont understand how the lights are working (ie- i dont see where the wig-wags are turn on and off). Maybe its me once again not understanding code.

This is my first attempt at programming the lights for the Jato
*/
#define led22
#define led33
#define led44
#define led55
#define led66
#define led77
#define led88
#define led99
#define led100
#define led110

#define T1 300
#define T2 100
#define T3 200

unsigned long cur,prv1=0,prv2=0,prv3=0;
int s1=0,s2=0,s3=0;

void setup(void)
{
pinMode(led22,OUTPUT); /* first set (wig-wag) */ <-------- error
pinMode(led33,OUTPUT);

pinMode(led44,OUTPUT); /* 2nd set (flashing yellow) */
pinMode(led55,OUTPUT);

pinMode(led66,OUTPUT); /*3rd set (2x blue/red) */
pinMode(led77,OUTPUT);
pinMode(led88,OUTPUT);
pinMode(led99,OUTPUT);

pinMode(led100,OUTPUT); /* 4rth set (headlights) */
pinMode(led110,OUTPUT);

digitalWrite(led100,HIGH); /* turn on headlights /
digitalWrite(led110,HIGH);
}
void loop(void)
{
cur = millis();
if(cur - prv1 >T1) /
set 1 - wig-wag /
{
prv1 = cur;
s1 = !s1;
digitalWrite(led22,s1);
digitalWrite(led33,!s1);
}
if(cur - prv2 > T2) /
set 2 - flash together */
{
prv2 = cur;
s2 = !s2;
digitalWrite(led44,s2);
digitalWrite(led55,s2);
}
if(cur - prv3 > T3)
{
prv3 = cur;
s3 = !s3;

thanks yet again!

(1) All of the led pin definitions should have the form

#define

The compiler is complaining because the definition of led22 is incomplete.

(2) The first line comment needs to begin with /*

and (3) you’ll need to add two closing braces following the code that you’ve shown - one to complete the final if statement, and one to complete the loop() function.

In the code I suggested, the LED identifiers ended with two digits: the first digit identified what you had called the set, and the second digit was intended to uniquely identify the LED within the set. You, of course, are free to label them however you choose, but please choose identifiers that will make sense six months from today.

Two strong suggestions:

(1) when you post code, click on the “#” button and paste your code between the pair of bracketed code and /code tags, click the “Preview” button, and check the preview before clicking on “Post”.

(2) Notice that C and C++ are “case sensitive”, meaning that uppercase letters are not interchangable with the same letter in lowercase.

Since you didn’t describe the behavior you wanted for the third set of lights, I didn’t provide any code. In order for the red and blue lights to do anything, you’ll need to learn enough to write that tiny bit of code…

Ok. I was able to see some of my faults quickly and had fixed some of them right after I sent my last reply. I did finally finish the code and it has passed. I took some time off from working on this because of frustration. I dont have enough resistors to finish setting up the breadboard to see how it operates. I still dont understand how the lights are going to wig-wag, flash, etc. From what basic understanding of making an led turn and off, I didnt see that anywhere. Was I suppose to add that?

/* This is my first attempt at programming the lights for the Jato */ int led2=2; int led3=3; int led4=4; int led5=5; int led6=6; int led7=7; int led8=8; int led9=9; int led10=10; int led11=11;

define T1 300

define T2 100

define T3 200

unsigned long cur,prv1=0,prv2=0,prv3=0; int s1=0,s2=0,s3=0;

void setup() { { pinMode(led2, OUTPUT); /* first set (wig-wag) / pinMode(led3, OUTPUT); } { pinMode(led4, OUTPUT); / 2nd set (flashing yellow) / pinMode(led5, OUTPUT); } { pinMode(led6, OUTPUT); /*3rd set (2x blue/red) */ pinMode(led7, OUTPUT); pinMode(led8, OUTPUT); pinMode(led9, OUTPUT); } { pinMode(led10, OUTPUT); / 4rth set (headlights) */ pinMode(led11, OUTPUT);

digitalWrite(led10,HIGH); /* turn on headlights / digitalWrite(led11,HIGH); } } void loop(void) { cur = millis(); if(cur - prv1 >T1) / set 1 - wig-wag / { prv1 = cur; s1 = !s1; digitalWrite(led2,s1); digitalWrite(led3,!s1); } if(cur - prv2 > T2) / set 2 - flash together / { prv2 = cur; s2 = !s2; digitalWrite(led4,s2); digitalWrite(led5,s2); } if(cur - prv3 > T3) / set 3 - blue/red */ { prv3 = cur; s3 = !s3; digitalWrite(led6,s3); digitalWrite(led7,s3); digitalWrite(led8,s3); digitalWrite(led9,s3); } }

Thank you for your support and patience!

  {
  pinMode(led2, OUTPUT); /* first set (wig-wag) */
  pinMode(led3, OUTPUT);
  }
  {
  pinMode(led4, OUTPUT); /* 2nd set (flashing yellow) */
  pinMode(led5, OUTPUT);
  }
  {
  pinMode(led6, OUTPUT); /*3rd set (2x blue/red) */
  pinMode(led7, OUTPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  }
  {
  pinMode(led10, OUTPUT); /* 4rth set (headlights) */
  pinMode(led11, OUTPUT);

  digitalWrite(led10,HIGH); /* turn on headlights */
  digitalWrite(led11,HIGH);
  }

None of the { or } are needed. They scream clueless. I'd advise removing them, to keep them from giving you away.

I still dont understand how the lights are going to wig-wag, flash, etc. From what basic understanding of making an led turn and off, I didnt see that anywhere. Was I suppose to add that?

Well, yeah.

I still don't understand how the lights are going to wig-wag, flash, etc. From what basic understanding of making an led turn and off, I didn't see that anywhere. Was I supposed to add that?

It's in the code I posted for you. Here's just the loop() function with (I hope) enough comments for you to grasp how it works:

/*----------------------------------------------------------------------------*/
/* loop() - Control Periodic Events                                           */
/*----------------------------------------------------------------------------*/
void loop(void)
{  cur = millis();                     /* Set cur to current time in msec     */
   /*-------------------------------------------------------------------------*/
   /* Set 1 - Wig-Wag                                                         */
   /*-------------------------------------------------------------------------*/
   if (cur - prv1 > T1)                /* Has T1 msec elapsed since prv1 set? */
   {  prv1 = cur;                      /* If so, update prv1 to current time  */
      s1 = !s1;                        /* Invert state of first LED in set    */
      digitalWrite(LED11,s1);          /* Write that state to 1st LED         */
      digitalWrite(LED12,!s1);         /* Write opposite state to 2nd LED     */
   }                                   /*  end: Set 1 processing              */
   /*-------------------------------------------------------------------------*/
   /* Set 2 - Flash together                                                  */
   /*-------------------------------------------------------------------------*/
   if (cur - prv2 > T2)                /* Has T2 msec elapsed since prv2 set? */
   {  prv2 = cur;                      /* If so, update prv2 to current time  */
      s2 = !s2;                        /* Invert state of both LEDs in set    */
      digitalWrite(LED21,s2);          /* Write that state to 1st LED         */
      digitalWrite(LED22,s2);          /* Write same state to 2nd LED         */
   }                                   /*  end: Set 2 processing              */
   /*-------------------------------------------------------------------------*/
   /* Set 3 - (Not sure what these do)                                        */
   /*-------------------------------------------------------------------------*/
   if (cur - prv3 > T3)                /* Has T3 msec elapsed since prv3 set? */
   {  prv3 = cur;                      /* If so, update prv3 to current time  */
      s3 = !s3;                        /* Don't know if this is useful...     */
      /*----------------------------------------------------------------------*/
      /* Replace this comment with whatever you want set 3 to do              */
      /*----------------------------------------------------------------------*/
   }                                   /*  end: Set 3 processing              */
}                                      /*  end: loop() function               */
/*----------------------------------------------------------------------------*/