简体   繁体   中英

Arduino "RGB" Light not Blinking

I just want to know that for RGB light to work on Arduino, is there any special code other than this

int rPin = 13;
int gPin = 12;
int bPin = 11;
String msg1 = "Enter the color : ";
String inpt;
void setup() {
  pinMode(rPin,OUTPUT);
  pinMode(gPin,OUTPUT);
  pinMode(bPin,HIGH);
  Serial.begin(9600);
}
void loop() {
  digitalWrite(rPin,HIGH);
  digitalWrite(gPin,HIGH);
  digitalWrite(bPin,HIGH);
}

RGB is not doing anything right now..

i guess there are some things missing out. First, you don't change the states of the leds to OFF in the loop. And second there's no delays. Even if you chnage the states, you must have some delays to see the blinking. here's a code I suggest, try it and see if the result is what you want:

int rPin = 13;
int gPin = 12;
int bPin = 11;
int period = 500; //blinking period in ms
//String msg1 = "Enter the color : "; not used in this example
//String inpt;
void setup() {
  pinMode(rPin,OUTPUT);
  pinMode(gPin,OUTPUT);
  pinMode(bPin,HIGH);
  Serial.begin(9600);
}
void loop() {
  digitalWrite(rPin,HIGH);
  delay(period);
  digitalWrite(rPin,LOW);

  digitalWrite(gPin,HIGH);
  delay(period);
  digitalWrite(gPin,LOW);

  digitalWrite(bPin,HIGH);
  delay(period);
  digitalWrite(bPin,LOW);

}

and of course you might put different periods for each led, depending on your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM