Tuesday, January 25, 2011

Arduino Severino + LED RGB

Arduino Severino, diimplementasikan untuk mengendalikan LED RGB secara Random, hasilnya:





List Program :
int ledrPin = 9;
int ledgPin = 10;    // LED connected to digital pin 9,10,11
int ledbPin = 11;
int ledShow = 13;
int faderValue;
int fadegValue;
int fadebValue;
int sw =0;

void setup()  { 
  pinMode(ledrPin,OUTPUT);
  pinMode(ledgPin,OUTPUT);
  pinMode(ledbPin,OUTPUT);
  pinMode(ledShow,OUTPUT); 
  Serial.begin(9600);
  faderValue=0;
  fadegValue=0;
  fadebValue=0;
  randomSeed(analogRead(0));
} 

void loop()   {
  faderValue=random(0,256);
  fadegValue=random(0,256);
  fadebValue=random(0,256);  
  if(sw==0){sw=1;digitalWrite(ledShow,HIGH);}
   else {sw=0;digitalWrite(ledShow,LOW);}
 analogWrite(ledrPin, faderValue);
 analogWrite(ledgPin, fadegValue);         
 analogWrite(ledbPin, fadebValue);
 delay(1000);         
}