10 Mayıs 2015 Pazar

RGB Led control via Push Buttons

        There are two push buttons, one for switching between red-green-blue colors where the other buttons is used to control the brightness of the color that is currently alight.

        When both buttons are pressed at the same time, the RGB led goes off and no color can be seen.

        The circuit diagrams (one made on digital environment, the other one is the implemented) and the datasheet of shift register can be seen below:


Digital Drawed Circuit


Implemented Circuit

 

      Here is a video available to see the outputs and how the system works:




Arduino Code :

/*
  Can KAVALOĞLU
*/

int bttnPin1 = 6;
int bttnPin2 = 7;
int LEDRed = 9;
int LEDGreen = 10;
int LEDBlue = 11;
int bttnValue1, bttnValue2;
int count = 0;
int pwm_value = 255;
 
void setup(){
  pinMode(LEDRed, OUTPUT);
  pinMode(LEDGreen, OUTPUT);
  pinMode(LEDBlue, OUTPUT);
  pinMode(bttnPin1, INPUT);
  pinMode(bttnPin2, INPUT);
  Serial.begin(9600);
}
 
void loop(){
  bttnValue1 = digitalRead(bttnPin1);
  bttnValue2 = digitalRead(bttnPin2);
  Serial.print("Button 1 : ");
  Serial.print(bttnValue1);
  Serial.print(" Button 2 : ");
  Serial.println(bttnValue2);
  if(bttnValue1 == HIGH && bttnValue2 == LOW){
      pwm_value = pwm_value - 20;
      if(count == 0){
      analogWrite(LEDRed, pwm_value);
      analogWrite(LEDBlue,0); 
      analogWrite(LEDGreen,0);
    }
    else if(count == 1){
      analogWrite(LEDRed, 0);
      analogWrite(LEDBlue,0); 
      analogWrite(LEDGreen,pwm_value);
    }
    else if(count == 2){
      analogWrite(LEDRed, 0);
      analogWrite(LEDBlue,pwm_value); 
      analogWrite(LEDGreen,0);
    }   
   delay(100); 
  }
      
  else if(bttnValue2 == HIGH && bttnValue1 == LOW){
    count++;
    count = count % 3;
    if(count == 0){
      analogWrite(LEDRed, pwm_value);
      analogWrite(LEDBlue,0); 
      analogWrite(LEDGreen,0);
    }
    else if(count == 1){
      analogWrite(LEDRed, 0);
      analogWrite(LEDBlue,0); 
      analogWrite(LEDGreen,pwm_value);
    }
    else if(count == 2){
      analogWrite(LEDRed, 0);
      analogWrite(LEDBlue,pwm_value); 
      analogWrite(LEDGreen,0);
    }    
    delay(100);
  }
  else if(bttnValue1 == HIGH && bttnValue2 == HIGH){
    analogWrite(LEDRed, 0);
    analogWrite(LEDBlue,0); 
    analogWrite(LEDGreen,0);
  }   
}


Hiç yorum yok:

Yorum Gönder