int latchPin = 2;//Pin connected to pin 12 (RCK) of 74HC595 int clockPin = 0;//Pin connected to pin 11 (SCK) of 74HC595 int dataPin = 1; //Pin connected to pin 14 (SER) of 74HC595 int buttonPin=4; // for the pushbutton int potPin=3; // for the potentiometer int val=0; // to store the state of the button int analog=0; // to store the value from ADC //holders for infromation you're going to pass to shifting function byte data; byte dataArray[10]; void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin, OUTPUT); pinMode(buttonPin,INPUT); pinMode(potPin,INPUT); //predefined array to store the different LED configurations // => 0 = LED ON // => 1 = LED OFF // IGNORE MSB VALUE AS WE ONLY HAVE 7 LED'S dataArray[0] = 0xFF; //0b11111111 => All off dataArray[1] = 0xBF; //0b10111111 dataArray[2] = 0x9F; //0b10011111 dataArray[3] = 0x8F; //0b10001111 dataArray[4] = 0x87; //0b10000111 dataArray[5] = 0x83; //0b10000011 dataArray[6] = 0x81; //0b10000001 dataArray[7] = 0x80; //0b10000000 => All on // THIS PART LIGHTS UP ALL THE LEDS IN A SEQUENCE AT STARTUP for (int j = 0; j < 8; j++) { data = dataArray[j]; //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, data); digitalWrite(latchPin, 1); delay(50); // adjust as needed } } void loop() { val = digitalRead(buttonPin); // read button state analog=analogRead(potPin); // read potentiometer value // Variable to store the count of the different tasks //(can be increased as needed provided the potentiometer divisions are also increased ) static int count1=0; // Task1 static int count2=0; // Task2 static int count3=0; // Task3 // Potentiometer divisions: [0-100 | 100-600 | 600-1023 ] => 3 divisions => 3 tasks // TASK1 if (analog <= 100) { if (count1 < 8) { //load the LED sequence you want from array data = dataArray[count1]; //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, data); //return the latch pin high at the end of transmission digitalWrite(latchPin, 1); //adjust delay to adjust switch response delay(50); } else { count1=0; // reset count when the all 7 LEDs are lit } if(val == 0){ count1++; // increment count when switch becomes low (or is pressed :- since its pulled up ) } } // TASK2 if (analog > 100 && analog <= 600 ) { if (count2 < 8) { //load the LED sequence you want from array data = dataArray[count2]; //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, data); //return the latch pin high at the end of transmission digitalWrite(latchPin, 1); //adjust delay to adjust switch response delay(50); } else { count2=0; // reset count when the all 7 LEDs are lit } if(val == 0){ count2++; // increment count when switch becomes low (or is pressed :- since its pulled up ) } } //TASK3 if (analog > 600) { if (count3 < 8) { //load the LED sequence you want from array data = dataArray[count3]; //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, data); //return the latch pin high at the end of transmission digitalWrite(latchPin, 1); //adjust delay to adjust switch response delay(50); } else { count3=0; // reset count when the all 7 LEDs are lit } if(val == 0){ count3++; // increment count when switch becomes low (or is pressed :- since its pulled up ) } } } //--------------------------------------------------------------------------------------------------------// // the heart of the program void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { // This shifts 8 bits out MSB first, //on the rising edge of the clock, //clock idles low //internal function setup int i=0; int pinState; pinMode(myClockPin, OUTPUT); pinMode(myDataPin, OUTPUT); //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0); //for each bit in the byte myDataOut� //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); //if the value passed to myDataOut and a bitmask result // true then... so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. if ( myDataOut & (1<