My first real RC truck project LED Arduino

Great start, but Dude, you gotta learn about functions! They'll save you a LOT of time, and increase your fun. :slight_smile:

Basically, a function is a bit of code you can re-use as much as you like. So you can code something once and reuse it instead of writing it several times over, like you did in your code.

You could also setup lights to blink as a right turn signal and a left turn signal. You'd call the function something like TurnSignal("left") and TurnSignal(right). Then in your loop(), which is a function itself, you may take some sort of input from a sensor that can tell when the wheels of your RC truck are turning and call your turnSignal() function with either the left or right argument. Then inside that you could use the case statement (http://www.arduino.cc/en/Reference/SwitchCase) to identify which argument and blink the appropriate lights.

That's be a pretty simple extension of your idea here. Hope it helps you continue in your fun. :slight_smile:

setup(){ /*something*/ }

loop(){ 
// set up the loop to always watch for a pin to go HIGH, meaning it is on 
// (I'm assuming a fictional sensor connected to this pin) and this will be 
// used to tell the turn signal to flash the right or left
  if (digitalRead(8) == HIGH) turnSignal("right")
  if (digitalRead(9) == HIGH) turnSignal("left")
}

void turnSignal(string direction) { //the turnSignal function takes an
// argument that is a string with a variable named direction, this isn't
// blinking, but you get the idea.
  switch (direction) {
    case "left":
        digitalWrite(pins[5], HIGH);
        digitalWrite(pins[4], HIGH);
        digitalWrite(pins[3], HIGH);
    case "right":
        digitalWrite(pins[5], HIGH);
        digitalWrite(pins[4], HIGH);
        digitalWrite(pins[3], HIGH);
  }

Oh, I haven't tested that code. It probably has errors, but is meant to explain the flow, not exactly how to do it. :slight_smile: