Go Down

Topic: My first real RC truck project LED Arduino (Read 1 time) previous topic - next topic

afap

you lost me here

int rightSequence[] = { 1,2,3}; // the pin index to use , 0 is the first of your CONNECTED pins (pin 2 in this example)
int leftSequence[] =  { 2,1,0}; // this is pin 4, pin 3, pin 2 (because 0 is pin 2, 1 is pin 3 etc)

pin0 is pin2 ?

mem

Its confusing because I left out a key piece of code in that post.

The sequenceLEDS routine should have added the firstPin value to the digital writes:

Code: [Select]
void sequenceLEDS( int *sequence , int length, int repeats)
{
 for( int counter=0; counter < repeats; counter++)
 {
   for( int i = 0; i < length; i++)
   {
     digitalWrite(sequence[i]+ firstPin ,HIGH);
     delay(100);  
   }
   for( int i = 0; i < length; i++)
   {
     digitalWrite(sequence[i]+ firstPin,LOW);
     delay(100);  
   }
 }    
}

This is still untested, but for example, with
[font=Courier New]  int leftSequence[] =  { 2,1,0};[/font]
this should do the following:
- digital write to firstPin + 2 (pin 4)
- digital write to firstPin + 1 (pin 3)
- digital write to firstPin + 0 (pin 2)


I hope that helps

afap

posting only half cods and cods that mite not work is not helping at all. I think you much not understand that i em very new to all this and dont under stand every thing.  so thats where im at.

Mike Mc

Pllleeeeeeeeeeeeeaaaaaasssssseeeeeeee post code inside the code quotes. Just click the littel hash icon when you are making your post and then paste your code where the cursor is located. That makes a nice code window with scrollbars so we don't have to scroll down acres of window to see your code.

Thanks.

afap

ok here is the code i would like to see made in to functions.  Please like i said im very new at this so no half cods or un checked codes. If you post it, make sure it works first. also please // and tell what each line of code dose. Thank you and if you need any more info please let me know.
Code: [Select]
int timer = 100;                   // The higher the number, the slower the timing.
int pins[] = { 2, 3, 4, 5, 6, 7 }; // an array of pin numbers
int num_pins = 6;                  // the number of pins (i.e. the length of the array)

void setup()
{
 int i;

 for (i = 0; i < num_pins; i++)   // the array elements are numbered from 0 to num_pins - 1
   pinMode(pins[i], OUTPUT);      // set each pin as an output
}

void loop()
{
 int i;

 for (i = 0; i < num_pins; i++) { // loop through each pin...
 
 }
 
   
//turn right
digitalWrite(pins[3], HIGH);
delay(100);
digitalWrite(pins[4], HIGH);
delay(100);
digitalWrite(pins[5], HIGH);
delay(100);

digitalWrite(pins[3], LOW);
delay(100);
digitalWrite(pins[4], LOW);
delay(100);
digitalWrite(pins[5], LOW);
delay(100);
digitalWrite(pins[3], HIGH);
delay(100);
digitalWrite(pins[4], HIGH);
delay(100);
digitalWrite(pins[5], HIGH);
delay(100);

digitalWrite(pins[3], LOW);
delay(100);
digitalWrite(pins[4], LOW);
delay(100);
digitalWrite(pins[5], LOW);
delay(100);
//turn left
digitalWrite(pins[2], HIGH);
delay(100);
digitalWrite(pins[1], HIGH);
delay(100);
digitalWrite(pins[0], HIGH);
delay(100);
digitalWrite(pins[2], LOW);
delay(100);
digitalWrite(pins[1], LOW);
delay(100);
digitalWrite(pins[0], LOW);
delay(100);
digitalWrite(pins[2], HIGH);
delay(100);
digitalWrite(pins[1], HIGH);
delay(100);
digitalWrite(pins[0], HIGH);
delay(100);
digitalWrite(pins[2], LOW);
delay(100);
digitalWrite(pins[1], LOW);
delay(100);
digitalWrite(pins[0], LOW);
delay(100);




 }


Thank you

Go Up