#include <Arduino.h>

// Data pin for the shift register
const int dataPin = 11;

// Clock pin for the shift register
const int clockPin = 10;

// Latch pin for the shift register
const int latchPin = 9;

// Array to store the state of the outputs
// 0 = off, 1 = on
int outputs[8] = {0, 0, 0, 0, 0, 0, 0, 0};

int btn1=6;
int btn2=5;
int btn3=7;

void setup() {
  // Set the data, clock, and latch pins as output
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(btn1, INPUT_PULLUP);
  pinMode(btn2, INPUT_PULLUP);
  pinMode(btn3, INPUT_PULLUP);
  // Set all outputs to off
  updateShiftRegister();
}

void loop() {
  // Turn on output 0
  if(digitalRead(btn1)==LOW){
    setOutput(0, 1);
  //delay(1000);
  }
  else{

  // Turn off output 0
  setOutput(0, 0);
  //delay(1000);
  }
  if(digitalRead(btn2)==LOW){
    setOutput(1, 1);
  //delay(1000);
  }
  else{

  // Turn off output 0
  setOutput(1, 0);
  //delay(1000);
  }
  if(digitalRead(btn3)==LOW){
    setOutput(2, 1);
  //delay(1000);
  }
  else{

  // Turn off output 0
  setOutput(2, 0);
  //delay(1000);
  }
  // Turn on output 1
  //setOutput(1, 1);
  //delay(1000);

  // Turn off output 1
  //setOutput(1, 0);
 // delay(1000);
}

// Function to set the state of a specific output
void setOutput(int output, int state) {
  outputs[output] = state;
  updateShiftRegister();
}

// Function to update the shift register with the current output state
void updateShiftRegister() {
  // Set latch pin low to start the transmission
  digitalWrite(latchPin, LOW);

  // Shift out the data
  for (int i = 7; i >= 0; i--) {
    digitalWrite(clockPin, LOW);
    digitalWrite(dataPin, outputs[i]);
    digitalWrite(clockPin, HIGH);
  }

  // Set latch pin high to latch the data
  digitalWrite(latchPin, HIGH);
}
74HC595