A
A
artanets12016-06-12 18:40:41
Arduino
artanets1, 2016-06-12 18:40:41

How to write the code to control the shift register using arduino?

How to correctly write code to control shift registers, LED drivers and any other radio components that are controlled using Clock and data input signals.
From what I have already found:
1. just manually enter the sequence of turning on and off the two arduino ports.

void loop() {
   digitalWrite(pin2, HIGH);
   delay(timer);
   digitalWrite(pin2, LOW);
   delay(timer);

   digitalWrite(pin3, HIGH);
   delay(timer);
   digitalWrite(pin3, LOW);
   delay(timer);

   digitalWrite(pin4, HIGH);
   delay(timer);
   digitalWrite(pin4, LOW);
   delay(timer);

   digitalWrite(pin5, HIGH);
   delay(timer);
   digitalWrite(pin5, LOW);
   delay(timer);

   digitalWrite(pin6, HIGH);
   delay(timer);
   digitalWrite(pin6, LOW);
   delay(timer);

   digitalWrite(pin7, HIGH);
   delay(timer);
   digitalWrite(pin7, LOW);
   delay(timer);

   digitalWrite(pin6, HIGH);
   delay(timer);
   digitalWrite(pin6, LOW);
   delay(timer);

   digitalWrite(pin5, HIGH);
   delay(timer);
   digitalWrite(pin5, LOW);
   delay(timer);

   digitalWrite(pin4, HIGH);
   delay(timer);
   digitalWrite(pin4, LOW);
   delay(timer);

   digitalWrite(pin3, HIGH);
   delay(timer);
   digitalWrite(pin3, LOW);
   delay(timer);
}

2. or using arrays.
void loop() {
  for (count=0;count<6;count++) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer);
  }

Is there a better way to control such devices?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2016-06-12
@GavriKos

In general, shift registers are perfectly controlled using the shiftOut function.
And your code is incomprehensible at all, especially the first one - the shift register is connected to three ports, and you have 6 ports there.

A
Alexander Gusev, 2016-06-12
@Sanchogus

For conventional shift registers, for example, here, via ShiftOut: http://wiki.amperka.ru/abstract-arduino:press-counter
If the principle itself is important, then look at the timing diagrams, or unpick this function.
I could be wrong, but like: set the level to data, put it into the register at the clock front, set the following, push it into the register again with the clock front, after clogging all 8 values, apply the required level to the latch, which will simultaneously set all clogged values ​​at the output register.

M
Michael, 2016-06-14
@Inkvizitor66

As a slightly more universal solution - spi as an interface. Through it, the functions of the controller to write to the register.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question