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();
   }
 }
}

2 yorum:

  1. Hello I'm trying to control 6 led's to turn on and off using buttons, could you possibly help me? thanks

    YanıtlaSil