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!

help

thank you..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  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); 
}
Topic archived. No new replies allowed.