logo

mercoledì 10 ottobre 2012

arduino Blink led rgb


In questo esempio vedremo come effettuare un blink con un led RGB e arduino, un intervallo di colori di 1 secondo ciascuno, rosso, verde, blu.



int red=9,
    green=10,
    blue=11,
    i=0,
    j=0,
    color[]={red, green, blue},  // since array counts start a 0, color[0]=9, color[1]=10, color[2]=11
    intensity[]={0, 0,0}; // one intensity level for each color

void setup()
{
  // set pins as outputs
  pinMode(red,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(blue,OUTPUT);

  // turn off all colors
  analogWrite(red,0);
  analogWrite(green,0);
  analogWrite(blue,0);
}
void loop()
{

  analogWrite(red,255); // turn on red
  delay(1000); // wait a sec
  analogWrite(red,0); // turn off red

  analogWrite(green,255); // turn on green
  delay(1000); // wait a sec
  analogWrite(green,0); // turn off green

  analogWrite(blue,255); // turn on blue
  delay(1000); // wait a sec
  analogWrite(blue,0); // turn off blue

}

Nessun commento:

Posta un commento