Creating a Program to control RBG LEDs

So I am just starting out to Arduino and the way I like to learn is by taking something I discover, making it work and then deconstructing it so that I can figure out the syntax.

I have been going off an instructibles project:

And there is some sample code there, but it looks like it is not complete, was hoping someone might be able to take a look at the code and help me to figure out what might be missing in order to make this run. Thanks!

Here is the code snippet:


int value = 0; 
  int LED1 = 0;
  int LED2 = 1;
  int LED3 = 2;
  int LED4 = 4;
  int LED5 = 7;
  int LED6 = 8;
  int LED7 = 12;
  int LED8 = 13;
  int LED9 = 14;
  int LED10 = 15;
  int LED11 = 16;
  int LED12 = 17;
  int RED1 = 3;
  int GREEN1 = 5;
  int BLUE1 = 6;
  int RED2 = 9;
  int GREEN2 = 10;
  int BLUE2 = 11;

void setup() 
{ 
  pinMode(LED1,OUTPUT);
  pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
pinMode(LED5,OUTPUT);
pinMode(LED6,OUTPUT);
pinMode(LED7,OUTPUT);
pinMode(LED8,OUTPUT);
pinMode(LED9,OUTPUT);
pinMode(LED10,OUTPUT);
pinMode(LED11,OUTPUT);
pinMode(LED12,OUTPUT);

digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED10,LOW);
digitalWrite(LED11,LOW);
digitalWrite(LED12,LOW);

Red1Off();
Blue1Off();
Green1Off();
Red2Off();
Blue2Off();
Green2Off();
}

void loop()
{

LEDOn(LED1);
LEDOn(LED2);
LEDOn(LED3);
LEDOn(LED4);
LEDOn(LED5);
LEDOn(LED6);
LEDOn(LED7);
LEDOn(LED8);
LEDOn(LED9);
LEDOn(LED10);
LEDOn(LED11);
LEDOn(LED12);

FadeUp(RED1,RED2,2);
delay(2000);
FadeDown(RED1,RED2,2);
FadeUp(GREEN1,GREEN2,2);
delay(2000);
FadeDown(GREEN1,GREEN2,2);
FadeUp(BLUE1,BLUE2,2);
delay(2000);
FadeDown(BLUE1,BLUE2,2);

Magenta1On ();
Magenta2On ();
delay (2000);
Magenta1Off();
Magenta2Off();
Cyan1On ();
Cyan2On();
delay (2000);
Cyan1Off ();
Cyan2Off();
Yellow1On ();
Yellow2On();
delay (2000);
Yellow1Off;
Yellow2Off();


Blue1On();
Cyan2On();
delay (2000);
Blue1Off();
Cyan2Off();
Green2On();
Yellow1On();
delay (2000);
Green2Off();
Yellow1Off();
Red1On();
Magenta2On();
delay (2000);
Red1Off();
Magenta2Off();
White1On();
White2On();
delay(2000);
White1Off();
White2Off();


Blue1On();
Cyan2On();
delay (2000);
Blue1Off();
Cyan2Off();
Green2On();
Yellow1On();
delay (2000);
Green2Off();
Yellow1Off();
Red1On();
Magenta2On();
delay (2000);
Red1Off();
Magenta2Off();
Red1On();
White2On();
delay(2000);
Red1Off();
White2Off();



LEDOff(LED1);
LEDOff(LED2);
LEDOff(LED3);
LEDOff(LED4);
LEDOff(LED5);
LEDOff(LED6);
LEDOff(LED7);
LEDOff(LED8);
LEDOff(LED9);
LEDOff(LED10);
LEDOff(LED11);
LEDOff(LED12);
Red1Off();
Blue1Off();
Green1Off();
Red2Off();
Blue2Off();
Green2Off();
White1Off();
White2Off();
Red1Off();
Green1Off();
Blue1Off();
Red2Off();
Green2Off();
Blue2Off();


Red1On();
Red2On();
LEDSp(125);
Red1Off();
Red2Off();
Blue1On();
Blue2On();
LEDSp(125);
Blue1Off();
Blue2Off();
Green1On();
Green2On();
LEDSp(125);
Green1Off();
Green2Off();
Magenta1On ();
Magenta2On ();
LEDSp(125);
Magenta1Off();
Magenta2Off();
Cyan1On ();
Cyan2On();
LEDSp(125);
Cyan1Off ();
Cyan2Off();
Yellow1On ();
Yellow2On();
LEDSp(125);
Yellow1Off;
Yellow2Off();
White1On();
White2On();
LEDSp(125);
White1Off();
White2Off();
Blue1On();
Cyan2On();
LEDSp(125);
Blue1Off();
Cyan2Off();
Green2On();
Yellow1On();
LEDSp(125);
Green2Off();
Yellow1Off();
Red1On();
Magenta2On();
LEDSp(125);
Red1Off();
Magenta2Off();
Red1On();
White2On();
LEDSp(125);
Red1Off();
White2Off();
Red1Off();
Green1Off();
Blue1Off();
Red2Off();
Green2Off();
Blue2Off();
Green1On();
Blue2On();
LEDSp2 (200);
Green1Off();
Blue2Off();
Green1On();
Blue2On();
LEDSp2 (200);
Green1Off();
Blue2Off();







}
void LEDSp (int x) { // spirals on from 1-n
LEDOn(LED1);
delay(x);
LEDOn(LED2);
delay(x);
LEDOn(LED3);
delay(x);
LEDOn(LED4);
delay(x);
LEDOn(LED5);
delay(x);
LEDOn(LED6);\
delay(x);
LEDOn(LED7);
delay(x);
LEDOn(LED8);
delay(x);
LEDOn(LED9);
delay(x);
LEDOn(LED10);
delay(x);
LEDOn(LED11);
delay(x);
LEDOn(LED12);

delay(x);
LEDOff(LED1);
delay(x);
LEDOff(LED2);
delay(x);
LEDOff(LED3);
delay(x);
LEDOff(LED4);
delay(x);
LEDOff(LED5);
delay(x);
LEDOff(LED6);
delay(x);
LEDOff(LED7);
delay(x);
LEDOff(LED8);
delay(x);
LEDOff(LED9);
delay(x);
LEDOff(LED10);
delay(x);
LEDOff(LED11);
delay(x);
LEDOff(LED12);
}

void LEDSp2 (int x) { // spirals on from 1-n
LEDOn(LED1);
delay(x);
LEDOff(LED1);
LEDOn(LED2);
delay(x);
LEDOff(LED2);
LEDOn(LED3);
delay(x);
LEDOff(LED3);

LEDOn(LED4);
delay(x);
LEDOff(LED4);
LEDOn(LED5);
delay(x);
LEDOff(LED5);
LEDOn(LED6);
delay(x);
LEDOff(LED6);
LEDOn(LED7);
delay(x);
LEDOff(LED7);
LEDOn(LED8);
delay(x);
LEDOff(LED8);
LEDOn(LED9);
delay(x);
LEDOff(LED9);
LEDOn(LED10);
delay(x);
LEDOff(LED10);
LEDOn(LED11);
delay(x);
LEDOff(LED11);
LEDOn(LED12);
delay(x);
LEDOff(LED12);

}

void LEDOn(int x) {
digitalWrite(x,HIGH);
}
void LEDOff(int x) {
digitalWrite(x,LOW);
}
void Red1On() {
analogWrite(RED1,100);
}
void Red1Off() {
analogWrite(RED1,255);
}
void Green1On() {
analogWrite(GREEN1,100);
}
void Green1Off() {
analogWrite(GREEN1,255);
}
void Blue1On() {
analogWrite(BLUE1,100);
}
void Blue1Off() {
analogWrite(BLUE1,255);
}
void Red2On() {
analogWrite(RED2,100);
}
void Red2Off() {
analogWrite(RED2,255);
}
void Green2On() {
analogWrite(GREEN2,100);
}
void Green2Off() {
analogWrite(GREEN2,255);
}
void Blue2On() {
analogWrite(BLUE2,100);
}
void Blue2Off() {
analogWrite(BLUE2,255);
}
void Yellow1On() {
analogWrite (RED1,100) ;
analogWrite (GREEN1,100);
}
void Yellow1Off() {
analogWrite (RED1,255);
analogWrite (GREEN1,255);
}
void Cyan1On() {
analogWrite (GREEN1,100);
analogWrite (BLUE1,100);
}
void Cyan1Off () {
analogWrite (GREEN1,255);
analogWrite (BLUE1,255);
}
void Magenta1On () {
analogWrite (RED1,100);
analogWrite (BLUE1,100);
}
void Magenta1Off () {
analogWrite (RED1,255);
analogWrite (BLUE1,255);
}
void White1On () {
analogWrite (RED1,100);
analogWrite (BLUE1,100);
analogWrite (GREEN1,100);
}
void White1Off () {
analogWrite (RED1,225);
analogWrite (BLUE1,225);
analogWrite (GREEN1,225);
}

void Yellow2On() {
analogWrite (RED2,100) ;
analogWrite (GREEN2,100);
}
void Yellow2Off() {
analogWrite (RED2,255);
analogWrite (GREEN2,255);
}
void Cyan2On() {
analogWrite (GREEN2,100);
analogWrite (BLUE2,100);
}
void Cyan2Off () {
analogWrite (GREEN2,255);
analogWrite (BLUE2,255);
}
void Magenta2On () {
analogWrite (RED2,100);
analogWrite (BLUE2,100);
}
void Magenta2Off () {
analogWrite (RED2,255);
analogWrite (BLUE2,255);
}
void White2On () {
analogWrite (RED2,100);
analogWrite (BLUE2,100);
analogWrite (GREEN2,100);
}
void White2Off () {
analogWrite (RED2,225);
analogWrite (BLUE2,225);
analogWrite (GREEN2,225);
}

void FadeUp(int colour,int colour2 ,int speed) {
for(value = 255 ; value >= 80;) // fade in (from min to max)
{

analogWrite(colour, value); // sets the value (range from 0 to 255)
analogWrite(colour2, value);
delay(20); // waits for 30 milli seconds to see the dimming effect
value = value - speed;
}

}

void FadeDown(int colour,int colour2, int speed) {
for(value = 80; value <= 255;) // fade out (from max to min)
{

analogWrite(colour, value);
analogWrite(colour2, value);
delay(20);
value = value + speed;
}
}

and the way I like to learn is by taking something I discover, making it work and then deconstructing it so that I can figure out the syntax.

So the syntax for posting code on this forum is to use the # icon to post code.
Go and modify your original post, highlight the code and hit the #, then it is in a form we can deal with.

Made the modification, any thoughts?

Well, it is horrible, poorly commented and bloated, but it compiles.
What do you think is missing?

Well other code that I have seen for the Arduino seem to have other elements, like defining certain settings. The instructibles guide referenced another project and I observed a few lines of code as such that I thought might need to be present in the project that I am working on, such as:

#include <EEPROM.h>                                // Include the EEPROM library

// Settings
#define crossTime 3000
#define changeTime 1500
#define waitTime 3000
#define beeps 50
#define beepLength 10
#define beepPitch 1
#define beepSilence 75

// PIN CONFIGUTRATION
#define redLed  13
#define yellowLed  12
#define greenLed  11
#define greenManLed  10
#define redManLed  9
#define button  6
#define waitLed  7
#define sounder  8

That's obviously for a different project, but do I also need to define pin configurations and settings for my project? Or is that what "int" is doing?

do I also need to define pin configurations and settings for my project?

That code has it.
The int defination coupled with the pinMode() in the setup defines your pins. Is that original code not running?

For a pin number, you can #define it (a macro substitution will be made in the code) or you can set a variable (or preferably a constant) to specify the pin number.
So

#define LED_PIN 13
const int ledPin = 13;

Would allow you to write pinMode (LED_PIN, OUTPUT); or

pinMode (ledPin, OUTPUT);

Is that what you meant?

I noticed that you are using analogue write to any pin. Do you know you can only use this on some pins, and these depends on what arduino you have.

No, I think the analogWrites are OK.
Judging by the values, common anode, but I guess that is explained in the instructable (who wrote that? It really is shockingly bad)

Most instructables I have seen are shockingly bad.

Best you don't look at this one Mike - I haven't found the current-limiting resistors yet...

Actually, he says explicitly that he doesn't use any current limiting resistors, but the pwm capabilities of the arduino to limit current. Wow.

Then he is a total idiot and should not be allowed to have a computer.
This tell you why he is so wrong and encouraging people to damage their arduinos.
http://www.thebox.myzen.co.uk/Tutorial/LEDs.html

Comment to that effect now posted on the source of this drivel.

Maybe s/he works for Atmel and is trying to boost AVR sales :wink:

Gentle reader, when we say "shorter code gives the bugs fewer dusty corners to hide in", this is the sort of thing we mean:

void White2On () 
{
  analogWrite (RED2,100);
  analogWrite (BLUE2,100);
  analogWrite (GREEN2,100);
}

void White2Off () 
{
  analogWrite (RED2,225);
  analogWrite (BLUE2,225);
  analogWrite (GREEN2,225);
}

(Common anode, remember)

Nearly 500 lines of code, for maybe a hundred lines of content.
{{facepalm}}