need a better code

hey there! i made this code for 4 rgb and 1 led on arduino uno and need code to turn the led/rgb led dimming! like it will trun on within a second but it will take time to off! :slight_smile:

int led = 13;
int ledDigitalOne[] = {14, 15, 16}; 
 
int ledDigitalTwo[] = {9, 10, 11}; 
 
int ledDigitalThree[] = {3, 5, 6};

int ledDigitalFour[] = {0, 1, 2};
 
const boolean ON = LOW; 

const boolean OFF = HIGH; 
 
 
const boolean RED[] = {ON, OFF, OFF}; 
const boolean GREEN[] = {OFF, ON, OFF}; 
const boolean BLUE[] = {OFF, OFF, ON}; 
const boolean YELLOW[] = {ON, ON, OFF}; 
const boolean CYAN[] = {OFF, ON, ON}; 
const boolean MAGENTA[] = {ON, OFF, ON}; 
const boolean WHITE[] = {ON, ON, ON}; 
const boolean BLACK[] = {OFF, OFF, OFF}; 

 
const boolean* COLORS[] = {RED, GREEN, BLUE, YELLOW, CYAN, MAGENTA, WHITE, BLACK}; 
 

void setup(){ 
for(int i = 0; i < 3; i++) { 
  pinMode(led, OUTPUT);
  
  pinMode(ledDigitalOne[i], OUTPUT); 

  pinMode(ledDigitalTwo[i], OUTPUT); 
 
  pinMode(ledDigitalThree[i], OUTPUT); 

  pinMode(ledDigitalFour[i], OUTPUT);
} 
} 

void loop(){ 

digitalWrite(led, HIGH);
delay(150);
digitalWrite(led, LOW);
delay(580);
/* Example - 1 Set a color Set the three LEDs to any predefined color*/ 
setColor(ledDigitalOne, RED); 
 
setColor(ledDigitalTwo, GREEN); 
 
setColor(ledDigitalThree, BLUE); 

setColor(ledDigitalFour, RED); 

/* Exampe - 2 Go through Random Colors Set the LEDs to a random color*/ 
int rand = random(0, sizeof(COLORS) / 2); 
 
setColor(ledDigitalOne, COLORS[rand]); 
 
rand = random(0, sizeof(COLORS) / 2); 
 
setColor(ledDigitalTwo, COLORS[rand]); 
rand = random(0, sizeof(COLORS) / 2); 
 
setColor(ledDigitalThree, COLORS[rand]); 

setColor(ledDigitalFour, COLORS[rand]);
delay(1000); 
} 

/* Sets an led to any color led - a three element array defining the three color pins (led[0] = redPin, led[1] = greenPin, led[2] = bluePin) color - a three element boolean array (color[0] = red value (LOW = on, HIGH = off), color[1] = green value, color[2] =blue value)*/ 
void setColor(int* led, boolean* color){ 
for(int i = 0; i < 3; i++) { 
digitalWrite(led[i], color[i]); 
} 
} 
/* A version of setColor that allows for using const boolean colors*/ 
void setColor(int* led, const boolean* color) { 
boolean tempColor[] = {color[0], color[1], color[2], color[3]}; 
setColor(led, tempColor); 
}

HELP! :cold_sweat:
THANK YOU :slight_smile:

Again, with code tags and without italics, please.

AWOL:
Again, with code tags and without italics, please.

That'd be item 7 here: http://forum.arduino.cc/index.php/topic,148850.0.html

code tags added by moderator.

code tags added by moderator.

I could've done that, but I don't like being SHOUTED at.

Shouted at??

Shouted at??

HELP!

Shouted at.

Ah.

prit18:
hey there! i made this code for 4 rgb and 1 led on arduino uno and need code to turn the led/rgb led dimming! like it will trun on within a second but it will take time to off! :slight_smile:

Right now you are using digitalWrite to turn pins on and off. To fade, you will need to use analog pins and analogWrite:

http://arduino.cc/en/Tutorial/PWM

The problem is, you are using 12 pins (three per LED x 4 LEDs) but many Arduino boards have only 6 PWM outputs. Which Arduino board (Uno/Leonardo/Mega/Due) are you using?