Go Down

Topic: need a better code (Read 820 times) previous topic - next topic

prit18

Aug 23, 2013, 05:44 pm Last Edit: Aug 23, 2013, 07:20 pm by CrossRoads Reason: 1
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!  :)

Code: [Select]


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!   :smiley-roll-sweat:
THANK YOU :)

AWOL

Again, with code tags and without italics, please.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Jack Christensen


Again, with code tags and without italics, please.


That'd be item 7 here: http://forum.arduino.cc/index.php/topic,148850.0.html
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

CrossRoads

code tags added by moderator.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

AWOL

Quote
code tags added by moderator.
I could've done that, but I don't like being SHOUTED at.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

AWOL

Quote
Shouted at??

Quote
HELP!

Shouted at.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

tylernt


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!  :)


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?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy