25 Şubat 2015 Çarşamba

LED control via Push Buttons combined with a Shift Register (74HC595)


        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


Datasheet for 74HC595 


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





Arduino Code :

/*
  Can KAVALOĞLU
*/

int DS_pin = 8;
int STCP_pin = 9;
int SHCP_pin = 10;
int buttonPin1 = 11;
int buttonPin2 = 12;
boolean registers[5];
int button1Value, button2Value;

void setup()
{
 pinMode(DS_pin,OUTPUT);
 pinMode(STCP_pin,OUTPUT);
 pinMode(SHCP_pin,OUTPUT);
 pinMode(buttonPin1, INPUT);
 pinMode(buttonPin2, INPUT);
 writeReg();
}

void writeReg()
{
  digitalWrite(STCP_pin, LOW);
  
  for (int i=0; i<=4; i++)
  {
    digitalWrite(SHCP_pin, LOW);
    digitalWrite(DS_pin, registers[i] );
    digitalWrite(SHCP_pin, HIGH);
  }
  
  digitalWrite(STCP_pin, HIGH);
  delay(100);
}

void loop()
{
 button1Value = digitalRead(buttonPin1);
 button2Value = digitalRead(buttonPin2);
 if(button1Value == HIGH && button2Value == LOW){
     for(int i=4; i>=0; i--)
     {
      registers[i] = HIGH;
      writeReg();
     }
    
     for(int i=0; i<=4; i++)
     {
      registers[i] = LOW;
      writeReg();
     }
 }
 else if (button1Value == LOW && button2Value == HIGH){
     for(int i=0; i<=4; i++)
     {
      registers[i] = HIGH;
      writeReg();
     }
  
     for(int i=4; i>=0; i--)
     {
      registers[i] = LOW;
      writeReg();
     }
 }
 else if (button1Value == HIGH && button2Value == HIGH){
   for(int i=2; i>=0; i--){
      registers[i] = HIGH;
      writeReg(); 
   }
   for(int i=0; i<2 data-blogger-escaped-for="" data-blogger-escaped-high="" data-blogger-escaped-i="" data-blogger-escaped-int="" data-blogger-escaped-low="" data-blogger-escaped-registers="" data-blogger-escaped-writereg="">=2; i--){
      registers[i] = LOW;
     writeReg();
   }
 }
}

RGB Led color change via LDR using Arduino.

       The circuit diagrams (one made on digital environment, the other one is the implemented) 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 LEDRed = 9;
int LEDGreen = 10;
int LEDBlue = 11;
int sensePin = 0;
int val;

void setup(){
  pinMode(LEDRed, OUTPUT);
  pinMode(LEDGreen, OUTPUT);
  pinMode(LEDBlue, OUTPUT);
  pinMode(sensePin, INPUT);
  Serial.begin(9600);
}

void loop(){
  val = analogRead(sensePin);
  Serial.println(val);
  if(val < 10){
   analogWrite(LEDRed, 0);
   analogWrite(LEDBlue,0); 
    analogWrite(LEDGreen,0);
  }
  else if (val<100) {
    analogWrite(LEDRed,0);
    analogWrite(LEDBlue,128); 
    analogWrite(LEDGreen,128);    
  } else if (val<200) {
    analogWrite(LEDRed,map(val,100,200,0,128));
    analogWrite(LEDBlue,map(val,100,200,128,0)); 
    analogWrite(LEDGreen,128);
  } else if (val<300) {
    analogWrite(LEDRed,128);
    analogWrite(LEDBlue,0); 
    analogWrite(LEDGreen,128);  
  } else if (val<400) {
    analogWrite(LEDRed,128);
    analogWrite(LEDBlue,map(val,200,400,0,128)); 
    analogWrite(LEDGreen,map(val,200,400,128,0));
  } else if (val<500) {
    analogWrite(LEDRed,128);
    analogWrite(LEDBlue,128); 
    analogWrite(LEDGreen,0);  
  } else if (val<800) {
    analogWrite(LEDRed,map(val,400,800,128,0));
    analogWrite(LEDBlue,128); 
    analogWrite(LEDGreen,map(val,800,400,0,128));
  }
  
}