Shift Register - Vibration Motor Issues

Dear Fellow Arduino Enthusiasts,

For a long time now, I have benefitted from this forum as someone who passively took advantage of the accumulated knowledge here. Now after tinkering the whole weekend, I am forced to ask the community to help me out with.

For a project I try to control eight vibration motors through a shift register (SN74HC595), I hooked the motors up with a diode and capacitor inbetween the output pin and the pins of the vibration motor (as described here.)
I thought I understood the basics of bit logic and modified the Adafruit code for led’s.

Now as I try to call one pin after the other, only one direction seems to work (leftToRight → see in code below), while shifting the bits the other way results in some strange behaviour. Serial output ( see in the coding attachment) seems to output the right values. (or not?)
Ideally I would like to be able to control the vibration motors singularly, as well as in stepped fashion.

I am pretty sure that my code has an issue and I would be really thankful for your suggestions or some help. Thanks!

int latchPin = 2;
int clockPin = 3;
int dataPin = 1;
 
byte vibro = 0;
int timerDelay = 150;



byte alternate1;

 
void setup() 
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);

 Serial.begin(9600);

}
 
void loop() 
{
  
leftToRight();
rightToLeft();

 
void updateShiftRegister(byte updatedByte)
{
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, LSBFIRST, updatedByte);
   digitalWrite(latchPin, HIGH);
}

void leftToRight(){
  byte alternate = 0b1000000;
  updateShiftRegister(alternate);
  delay(timerDelay);
  for (int i = 0; i <= 7; i++)
  {
    byte alternate1 = alternate >> i;
    Serial.println(alternate1,BIN);
    updateShiftRegister(alternate1);
    delay(timerDelay);
  }
}

void rightToLeft(){
  byte alternate = 0b0000001;
  updateShiftRegister(alternate);
  delay(timerDelay);
  for (int i = 0; i <= 7; i++)
  {
    byte alternate1 = alternate << i;
    Serial.println(alternate1,BIN);
    updateShiftRegister(alternate1);
    delay(timerDelay);
  }
}

The 74HC595 only works in one direction.... Qa => Qh

Allan

Dear Allan,

Thank you very much for the quick reply, this makes sense... I heard about bidirectional shift registers before, maybe thats what I need then...

Lukas

Or you could write a complete 8 bits with the pattern you want every time, and then operate the output latch when that’s done.

Allan…