2pcs 74HC595 with 16ch led + potentiometer.

First: dataPin,latchPin,clockPin is the same pin for all 74HC595 which I have on PCB (2x 74hc595 to drive 16ch leds and 1x 74hc595 to drive ULN2003) it is correct?

Second:

int LEDpin = 5;       // LED on pin 5
int switchPin = 13;   // momentary switch on 13, other side connected to ground

boolean running = false;

void setup()
{
 pinMode(LEDpin, OUTPUT);
 pinMode(switchPin, INPUT);
 digitalWrite(switchPin, HIGH);      // turn on pullup resistor
}

void loop()
{
 if (digitalRead(switchPin) == LOW)
 {  // switch is pressed - pullup keeps pin high normally
   delay(100);                        // delay to debounce switch
   running = !running;                // toggle running variable
   digitalWrite(LEDpin, running);      // indicate via LED
 }
}

I haven't tactswitch/momentary switch. I have remote control. Second I have 74HC595 not only atmega so for me its strange to do this correctly.

Maybe this?

int latchPin = 4;
int clockPin = 5;
int dataPin = 3;
int shiftValue = 0;

#define Out1Pin = X; // I don't know which port if I have there 74HC595???

boolean running = false;

#include <IRremote.h>
#define irPin 8  // pin dla TSOP
IRrecv irrecv(irPin);
decode_results results;

void setup()

{

     irrecv.enableIRIn();

   pinMode(latchPin, OUTPUT);
   pinMode(dataPin, OUTPUT);  
   pinMode(clockPin, OUTPUT);
  
   pinMode(Out1Pin, OUTPUT); // OUTPUT?

   digitalWrite(X, LOW); // I don't know which port if I have there 74HC595???

}

void loop() {

if (irrecv.decode(&results))
   {
        if (digitalRead(Out1Pin) == LOW)
       switch (results.value)
                {
                      {
         case 0x801:  // kod klawisza 1
            running = !running; 

            break;
                       }
                }
   irrecv.resume();
    }


digitalWrite (latchPin, LOW);
shiftOut (dataPin, clockPin, MSBFIRST, highByte (shiftValue)); // upper 8 bits
shiftOut (dataPin, clockPin, MSBFIRST, lowByte (shiftValue)); // lower 8  bits
digitalWrite (latchPin, HIGH);
  delay(100); // remove this line after testing

                }

dataPin,latchPin,clockPin is the same pin for all 74HC595 which I have on PCB (2x 74hc595 to drive 16ch leds and 1x 74hc595 to drive ULN2003) it is correct?

No.
The data pin must go only to the first shift register, the second shift register takes its data from the most significant output of the first and the third from the most significant output of the second.

In that way they are chained.

Ok. I will fix this. But.. Please.. I don't know what change in my code to have working boolean.

Fixed. I connected thirds 73hc595 pin DS to QH' second 74HC595

Ok. So I have something whick work in 50% :slight_smile:

const byte LDRpin = A2; // LDR connected to pin A1 and ground (A0 is used for the pot)
const byte PWMpin = 10; // connected to the two OE pins
int lightValue = 50; // change/experiment with this value
int darkValue = 160; // change/experiment with this value
int LDRvalue;
byte PWMvalue;


int SER_Pin = 3;   //pin 14 on the 75HC595
int RCLK_Pin = 4;  //pin 12 on the 75HC595
int SRCLK_Pin = 5; //pin 11 on the 75HC595

int potPin = 0;
int potValue = 0;
int shiftValue = 0;

//How many of the shift registers - change this
#define number_of_74hc595s 3

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

#define VolUpPin 10 //up
#define VolDownPin A1 //down

#include <IRremote.h>
#define irPin 8  // pin dla TSOP

IRrecv irrecv(irPin);
decode_results results;

void setup() {

 
     irrecv.enableIRIn();
     
   pinMode(VolUpPin, OUTPUT);
   pinMode(VolDownPin, OUTPUT);
   
   pinMode(LDRpin, INPUT_PULLUP); // enables the internal pull up resistor
   pinMode(PWMpin, OUTPUT); // make the pin an output

   digitalWrite(10, LOW);
   digitalWrite(A1, LOW);


   pinMode(SER_Pin, OUTPUT);
   pinMode(RCLK_Pin, OUTPUT);
   pinMode(SRCLK_Pin, OUTPUT);


   //reset all register pins
   clearRegisters();
   writeRegisters();
}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
  writeRegisters();
} 

//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

void loop() {
  LDRvalue = analogRead(LDRpin);
  LDRvalue = constrain(LDRvalue, lightValue , darkValue);
  PWMvalue = map(LDRvalue, lightValue, darkValue, 0, 220);
  analogWrite(PWMpin, PWMvalue); // write to the OE pins

if (irrecv.decode(&results))
   {
       switch (results.value)
       {
         case 0x801:  // kod klawisza 1
             setRegisterPin(16, LOW); 
            break;
            
         case 0x1:  // kod klawisza 1
             setRegisterPin(16, HIGH); 
            break;
            
         case 0x802:  // kod klawisza 2
              setRegisterPin(17, LOW);
            break;
            
         case 0x2:  // kod klawisza 2
              setRegisterPin(17, HIGH);
            break;
            
         case 0x803:  // kod klawisza 3
            //digitalWrite(Out3Pin, LOW);
              setRegisterPin(18, LOW);
            break;
            
         case 0x3:  // kod klawisza 3
              setRegisterPin(18, HIGH);
            break;
            
         case 0x80D:  // kod klawisza 4
              setRegisterPin(19, LOW);
            break;
            
         case 0xD:  // kod klawisza 4
              setRegisterPin(19, HIGH);
            break;

         case 0x807:  // kod klawisza 7 CH1
              setRegisterPin(20, LOW);
            break;
            
         case 0x7:  // kod klawisza 7 CH1
             setRegisterPin(20, HIGH);
            break;      
                  
          case 0x808:  // kod klawisza 8 CH2
            setRegisterPin(21, LOW);
            break;
            
         case 0x8:  // kod klawisza 8 CH2
            setRegisterPin(21, HIGH);
            break;  
                     
          case 0x809:  // kod klawisza 9 CH3
              setRegisterPin(22, LOW);
            break;
            
         case 0x9:  // kod klawisza 9 CH3
              setRegisterPin(22, HIGH);
            break;  

            
         case 0x11:  // kod klawisza 5
            digitalWrite(VolUpPin, LOW);
            delay(250);
            digitalWrite(VolDownPin, LOW);
            break;
            
         case 0x811:  // kod klawisza 5
            digitalWrite(VolUpPin, HIGH);
            delay(250);
            digitalWrite(VolUpPin, LOW);
            break;
            
         case 0x10:  // kod klawisza 6
            digitalWrite(VolDownPin, LOW);
            delay(250);
            digitalWrite(VolUpPin, LOW);
            break;
            
         case 0x810:  // kod klawisza 6
            digitalWrite(VolDownPin, HIGH);
            delay(250);
            digitalWrite(VolDownPin, LOW);
            break;
            
         case 0x80C:  // kod klawisza OFF
            //digitalWrite(Out1Pin, HIGH);
            break;
            
         case 0xC:  // kod klawisza OFF
            //digitalWrite(Out1Pin, LOW);
            break;


         }
   irrecv.resume();
   }

// read pot &  update outputs to 2 daisy chained shift registers
potValue = analogRead(A0);

if ( potValue >=0 && potValue <=20)
{
setRegisterPin(0, LOW);
}

if ( potValue >=20 && potValue <=63)
{
setRegisterPin(1, LOW);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(2, LOW);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(3, LOW);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(4, LOW);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(5, LOW);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(6, LOW);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(7, LOW);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, LOW);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(9, LOW);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(10, LOW);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(11, LOW);
}

if ( potValue >=693 && potValue <=756)
{
setRegisterPin(12, LOW);
}

if ( potValue >=756 && potValue <=819)
{
setRegisterPin(13, LOW);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(14, LOW);
}

if ( potValue >=882 && potValue <=945)
{
setRegisterPin(15, LOW);
}

if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(16, LOW);
}

if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, LOW);
}



  writeRegisters();
  delay(100);
  //clearRegisters();
}

Remote control works. But 16ch leds with potentiometer isn't working.

Second question:

It is ok? Only 100nF and 10k for TPIC6C595? (I have this values from datesheet)

const byte LDRpin = A2; // LDR connected to pin A1 and ground (A0 is used for the pot)
const byte PWMpin = 10; // connected to the two OE pins
int lightValue = 50; // change/experiment with this value
int darkValue = 160; // change/experiment with this value
int LDRvalue;
byte PWMvalue;


int SER_Pin = 3;   //pin 14 on the 75HC595
int RCLK_Pin = 4;  //pin 12 on the 75HC595
int SRCLK_Pin = 5; //pin 11 on the 75HC595

int potPin = 0;
int potValue = 0;
int shiftValue = 0;

//How many of the shift registers - change this
#define number_of_74hc595s 3

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

#define VolUpPin 10 //up
#define VolDownPin A1 //down

#include <IRremote.h>
#define irPin 8  // pin dla TSOP

IRrecv irrecv(irPin);
decode_results results;

void setup() {

 
     irrecv.enableIRIn();
     
   pinMode(VolUpPin, OUTPUT);
   pinMode(VolDownPin, OUTPUT);
   
   pinMode(LDRpin, INPUT_PULLUP); // enables the internal pull up resistor
   pinMode(PWMpin, OUTPUT); // make the pin an output

   digitalWrite(10, LOW);
   digitalWrite(A1, LOW);


   pinMode(SER_Pin, OUTPUT);
   pinMode(RCLK_Pin, OUTPUT);
   pinMode(SRCLK_Pin, OUTPUT);


   //reset all register pins
   clearRegisters();
   writeRegisters();
}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
  writeRegisters();
} 

//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)
void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}

void loop() {
  LDRvalue = analogRead(LDRpin);
  LDRvalue = constrain(LDRvalue, lightValue , darkValue);
  PWMvalue = map(LDRvalue, lightValue, darkValue, 0, 220);
  analogWrite(PWMpin, PWMvalue); // write to the OE pins

if (irrecv.decode(&results))
   {
       switch (results.value)
       {
         case 0x801:  // kod klawisza 1
             setRegisterPin(16, LOW); 
            break;
            
         case 0x1:  // kod klawisza 1
             setRegisterPin(16, HIGH); 
            break;
            
         case 0x802:  // kod klawisza 2
              setRegisterPin(17, LOW);
            break;
            
         case 0x2:  // kod klawisza 2
              setRegisterPin(17, HIGH);
            break;
            
         case 0x803:  // kod klawisza 3
            //digitalWrite(Out3Pin, LOW);
              setRegisterPin(18, LOW);
            break;
            
         case 0x3:  // kod klawisza 3
              setRegisterPin(18, HIGH);
            break;
            
         case 0x80D:  // kod klawisza 4
              setRegisterPin(19, LOW);
            break;
            
         case 0xD:  // kod klawisza 4
              setRegisterPin(19, HIGH);
            break;

         case 0x807:  // kod klawisza 7 CH1
              setRegisterPin(20, LOW);
            break;
            
         case 0x7:  // kod klawisza 7 CH1
             setRegisterPin(20, HIGH);
            break;      
                  
          case 0x808:  // kod klawisza 8 CH2
            setRegisterPin(21, LOW);
            break;
            
         case 0x8:  // kod klawisza 8 CH2
            setRegisterPin(21, HIGH);
            break;  
                     
          case 0x809:  // kod klawisza 9 CH3
              setRegisterPin(22, LOW);
            break;
            
         case 0x9:  // kod klawisza 9 CH3
              setRegisterPin(22, HIGH);
            break;  

            
         case 0x11:  // kod klawisza 5
            digitalWrite(VolUpPin, LOW);
            delay(250);
            digitalWrite(VolDownPin, LOW);
            break;
            
         case 0x811:  // kod klawisza 5
            digitalWrite(VolUpPin, HIGH);
            delay(250);
            digitalWrite(VolUpPin, LOW);
            break;
            
         case 0x10:  // kod klawisza 6
            digitalWrite(VolDownPin, LOW);
            delay(250);
            digitalWrite(VolUpPin, LOW);
            break;
            
         case 0x810:  // kod klawisza 6
            digitalWrite(VolDownPin, HIGH);
            delay(250);
            digitalWrite(VolDownPin, LOW);
            break;
            
         case 0x80C:  // kod klawisza OFF
            //digitalWrite(Out1Pin, HIGH);
            break;
            
         case 0xC:  // kod klawisza OFF
            //digitalWrite(Out1Pin, LOW);
            break;


         }
   irrecv.resume();
   }

// read pot &  update outputs to 2 daisy chained shift registers
potValue = analogRead(A0);

if ( potValue >=0 && potValue <=20)
{
setRegisterPin(1, HIGH);
}

if ( potValue >=20 && potValue <=63)
{
setRegisterPin(15, HIGH);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(14, HIGH);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(13, HIGH);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(12, HIGH);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(11, HIGH);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(10, HIGH);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(9, HIGH);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, HIGH);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(7, HIGH);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(6, HIGH);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(5, HIGH);
}

if ( potValue >=693 && potValue <=756)
{
setRegisterPin(4, HIGH);
}

if ( potValue >=756 && potValue <=819)
{
setRegisterPin(3, HIGH);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(2, HIGH);
}

if ( potValue >=882 && potValue <=945)
{
setRegisterPin(1, HIGH);
}

if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(0, HIGH);
}

if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, LOW);
}



  writeRegisters();
  delay(10);
  //clearRegisters();
}

Potentiometer works, but only in one direction. If I set 100% and all led are on, then if i go back to 0% all leds are still on.

Some ideas?

Please tell me about SRCLR / CLR pin. It must be connected directly to arduino or it must be connected by 10kR to VCC?

(tpic6C595)

Potentiometer works, but only in one direction. If I set 100% and all led are on, then if i go back to 0% all leds are still on.

That is because your code never turns them off.

Just after the pot reading then have a small loop to set all the register pins to low.

The CLR is a clear pin, when it is taken low all the shift register outputs get set to zero.
If you don't want that feature then pull it up high through a 10K.

The SRCLK is the serial clock sometimes called just clock and must be pulsed by the Arduino.

Thanks. I will test new code at the weekend.

Grumpy_Mike:
Just after the pot reading then have a small loop to set all the register pins to low.

If I will set all the register pins to low that will clear my set from third register? Won't it? (Third register works after I press 1,2,3,7,8,9 on remote control - on my code You can see)

Or that will help:

if ( potValue >=0 && potValue <=20)
{
setRegisterPin(15, HIGH);
}

if ( potValue >=20 && potValue <=63)
{
setRegisterPin(15, HIGH);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(14, HIGH);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(13, HIGH);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(12, HIGH);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(11, HIGH);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(10, HIGH);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(9, HIGH);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, HIGH);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(7, HIGH);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(6, HIGH);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(5, HIGH);
}

if ( potValue >=693 && potValue <=756)
{
setRegisterPin(4, HIGH);
}

if ( potValue >=756 && potValue <=819)
{
setRegisterPin(3, HIGH);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(2, HIGH);
}

if ( potValue >=882 && potValue <=945)
{
setRegisterPin(1, HIGH);
}

if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(0, HIGH);
}

if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, HIGH);
}


//set pin to LOW
if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, LOW);
}

if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(0, LOW);
}


if ( potValue >=882 && potValue <=945)
{
setRegisterPin(1, LOW);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(2, LOW);
}

if ( potValue >=756 && potValue <=819)
{
setRegisterPin(3, LOW);
}


if ( potValue >=693 && potValue <=756)
{
setRegisterPin(4, LOW);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(5, LOW);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(6, LOW);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(7, LOW);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, LOW);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(9, LOW);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(10, LOW);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(11, LOW);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(12, LOW);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(13, LOW);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(14, LOW);
}

if ( potValue >=20 && potValue <=63)
{
setRegisterPin(15, LOW);
}

if ( potValue >=0 && potValue <=20)
{
setRegisterPin(15, LOW);
}

Grumpy_Mike:
The SRCLK is the serial clock sometimes called just clock and must be pulsed by the Arduino.

SRCLK = SRCK?

Have a good day!

Regards

SRCLK = SRCK?

Yes.

If I will set all the register pins to low that will clear my set from third register? Won't it?

Only if you write the code to do that.

You have a load of
setRegisterPin(x, HIGH);
In response to the pot. I was suggesting that you set then all low BEFORE your code that sets some high in response to the pot value.
That way it will work with the pot going both up and down.
The way you are trying to do this is very long winded but it will work if you blank out the LEDs before you set some of them. Note you are doing this before these bits are displayed so you will never see all the LEDs go off.

It is possible to write in one line all pins which I need?

like:

setRegisterPin(0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15, LOW);

?

Now I have this:

// read pot &  update outputs to 2 daisy chained shift registers
potValue = analogRead(A0);

setRegisterPin(0, LOW);
setRegisterPin(1, LOW);
setRegisterPin(2, LOW);
setRegisterPin(3, LOW);
setRegisterPin(4, LOW);
setRegisterPin(5, LOW);
setRegisterPin(6, LOW);
setRegisterPin(7, LOW);
setRegisterPin(8, LOW);
setRegisterPin(9, LOW);
setRegisterPin(10, LOW);
setRegisterPin(11, LOW);
setRegisterPin(12, LOW);
setRegisterPin(13, LOW);
setRegisterPin(14, LOW);
setRegisterPin(15, LOW);


if ( potValue >=0 && potValue <=20)
{
setRegisterPin(15, HIGH);
setRegisterPin(14, HIGH);
setRegisterPin(13, HIGH);
setRegisterPin(12, HIGH);
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=20 && potValue <=63)
{
setRegisterPin(15, HIGH);
setRegisterPin(14, HIGH);
setRegisterPin(13, HIGH);
setRegisterPin(12, HIGH);
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(14, HIGH);
setRegisterPin(13, HIGH);
setRegisterPin(12, HIGH);
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(13, HIGH);
setRegisterPin(12, HIGH);
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(12, HIGH);
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=693 && potValue <=756)
{
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}


if ( potValue >=756 && potValue <=819)
{
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);

}

if ( potValue >=882 && potValue <=945)
{
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(0, HIGH);
}

if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, HIGH);
}

But there are too much code. So function like that "setRegisterPin(0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15, LOW);" will be perfect.

It is possible to write in one line all pins which I need?

like:

setRegisterPin(0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15, LOW);

No. But it is possible to do this:-

for(int i = 0; i<16 ; i++){
setRegisterPin(i, LOW);
}

Yes, I have checked this and it works. But I need this also for:

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

and this, for example:

if ( potValue >=252 && potValue <=315)
{
  for(int i=0; i<11; i++)
{
  setRegisterPin(i, HIGH);
}
}

isn't work.

If that last bit of code didn't work the you are doing something else wrong as well. As to the first lump of code you need to use the new technique in the second piece of code.

Why have you changed that first code? You seem to be going backwards.

No.. Please check actual code..

// read pot &  update outputs to 2 daisy chained shift registers
potValue = analogRead(A0);


for(int i=0; i<16; i++)
{
  setRegisterPin(i, LOW);
}


if ( potValue >=0 && potValue <=63)
{
setRegisterPin(15, HIGH);
setRegisterPin(14, HIGH);
setRegisterPin(13, HIGH);
setRegisterPin(12, HIGH);
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=63 && potValue <=126)
{
setRegisterPin(14, HIGH);
setRegisterPin(13, HIGH);
setRegisterPin(12, HIGH);
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=126 && potValue <=189)
{
setRegisterPin(13, HIGH);
setRegisterPin(12, HIGH);
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=189 && potValue <=252)
{
setRegisterPin(12, HIGH);
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=252 && potValue <=315)
{
setRegisterPin(11, HIGH);
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=315 && potValue <=378)
{
setRegisterPin(10, HIGH);
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=378 && potValue <=441)
{
setRegisterPin(9, HIGH);
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=441 && potValue <=504)
{
setRegisterPin(8, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=504 && potValue <=567)
{
setRegisterPin(7, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=567 && potValue <=630)
{
setRegisterPin(6, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=630 && potValue <=693)
{
setRegisterPin(5, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=693 && potValue <=756)
{
setRegisterPin(4, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}


if ( potValue >=756 && potValue <=819)
{
setRegisterPin(3, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=819 && potValue <=882)
{
setRegisterPin(2, HIGH);
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);
}

if ( potValue >=882 && potValue <=945)
{
setRegisterPin(1, HIGH);
setRegisterPin(0, HIGH);

}



if ( potValue >=945 && potValue <=1010)
{
setRegisterPin(0, HIGH);
}

if ( potValue >=1010 && potValue <=1023)
{
setRegisterPin(0, LOW);
setRegisterPin(1, LOW);
setRegisterPin(2, LOW);
setRegisterPin(3, LOW);
setRegisterPin(4, LOW);
setRegisterPin(5, LOW);
setRegisterPin(6, LOW);
setRegisterPin(7, LOW);
setRegisterPin(8, LOW);
setRegisterPin(9, LOW);
setRegisterPin(10, LOW);
setRegisterPin(11, LOW);
setRegisterPin(12, LOW);
setRegisterPin(13, LOW);
setRegisterPin(14, LOW);
setRegisterPin(15, LOW);
}

Hello.

I have question about TPIC TPIC6C595DG4 TEXAS INSTRUMENTS - IC: peripheral circuit | 8bit,shift register; SMD; SO16; -40÷125°C | TME - Electronic components

It has 8x 100mA per channel or max.100mA for all device so 8x 12,5mA?

From the "Absolute max ratings table"

"Continuous drain current, each output, all outputs on, I D , T C = 25°C 100 mA"

Type B (150mA) is offered on ebay for ~$0.50
Leo..

So for relays I added ULN2003 on output of TPIC. I have no space to solder "B" type.

I order new PCB (second version). I will tested new software in about a one week.

gavron04:
So for relays I added ULN2003 on output of TPIC.

Can't do that.
The ULN needs input voltage. The TPIC output is sink only.

The ULN also has a dropout voltage of ~1.5volt@100mA.
Are your relays ok with that.
Leo..

In first PCB I have atmega > uln2003 and relays. It works without problem when I have power ON:

2x relpol rm84 RM84-2012-35-1005 RELPOL - Relay: electromagnetic | DPDT; Ucoil: 5VDC; 8A; 8A/250VAC; 8A/24VDC | TME - Electronic components
2x zettler AZ822-2C-5DSE ZETTLER - Przekaźnik: elektromagnetyczny | DPDT; Ucewki : 5VDC; 2A; 1A/24VDC | TME - Części elektroniczne
1x nais https://www.piekarz.pl/pl/?item=1919

I have 4,13VDC on relays.

If only one zettler is on I have 4,28VDC

On power supply I have 5,016VDC

If this relays are on:
2x relpol rm84
2x zettler
1x nais

I have 5,010VDC on power supply.

So i think its ok?

Also the ULN and TPIC in this circuit will be ok? :slight_smile: