Hi all,
I am running 8 led's through a shift register. In the void part of the sketch the shiftOut instruction nominates MSBFIRST. This illuminates the led's from left to right IE pin 15 to pin 7. I have cut and pasted the first part and changed the MSBFIRST to LSBFIRST. My intention was that the led's would illuminate from left to right "MSBFIRST" and then from right to left "LSBFIRST". IE pin 7 back to pin 15. What is actually happening is that only the LSBFIRST running. Any ideas?
Thanks,
Davy.
int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
int outputEnablePin = 3;
byte leds = 0;
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(outputEnablePin, OUTPUT);
}
void loop()
{
setBrightness(255);
leds = 0;
updateShiftRegister();
delay(500);
for (int i = 0; i < 8; i++)
{
bitSet(leds, i);
updateShiftRegister();
delay(500);
}
for (byte b = 255; b > 0; b--)
{
setBrightness(b);
delay(50);
}
}
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, leds);
digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
void setBrightness(byte brightness) // 0 to 255
{
analogWrite(outputEnablePin, 255-brightness);
}
You are shifting out both "MSB" and "LSB" almost simultaneously. You should first turn on all LED's as "MSB", then you should clear all LED's before you turn on all LED's as "LSB".
looks like your updateShiftRegister() outputs the MSB and then the LSB, immediately following one another.
doesn't appear the shiftOut() actuallys shifts the value it is given, it simply "clocks" the MSB/LSB bit out.
if you want to clock a set of bits out, seems that you should set the MSB/LSB bit to the value you want and call shiftOut() with the appropriate arguments. (you might as well set leds to a 1/0. not need to use bitSet() and output the LSB. (however, in my simple experiment is seemed that LSB/MSBFIRST were reversed)
suggest you set dataPin to the built in LED to verify your understanding of these functions
Hi Danois,
Thanks for your reply. I have added your instructions and get the following error message.
//On
for (int i = 0; i < 8; i++)
{
bitSet(leds, i);
updateShiftRegister(direction); // This line says too many arguments to function 'void
updateShiftRegister()'
delay(500);