I have 5 LEDs a potentiometer and a m74hc59581 shift register.
As far as I know, everything is correct but no LEDs will light when I twist the pot.
Here is the code, if this isn't it I'll assume I looked at a bad datasheet for my shift registers pinoutpinout.
int dataPin = 8;
int latchPin = 10;
int clockPin = 12;
int potPin = A0;
int val = 0;
int shiftVal = 0;
void setup()
{
pinMode (latchPin, OUTPUT);
pinMode (clockPin, OUTPUT);
pinMode (dataPin, OUTPUT);
pinMode (potPin, INPUT);
}
void loop()
{
digitalWrite(latchPin, LOW);
val = analogRead(potPin);
val = map(val, 0, 1023, 0, 25);
if (val >= 0 && val < 5) {
int shiftVal = 64;
}
else if (val >= 6 && val <= 10) {
shiftVal = 96;
}
else if (val >= 11 && val <= 15) {
int shiftVal = 112;
}
else if (val >= 16 && val <= 20) {
int shiftVal = 120;
}
else if (val >= 21 && val <= 25) {
int shiftVal = 124;
}
else {
int shiftVal = 0;
}
shiftOut(dataPin, clockPin, MSBFIRST, shiftVal);
digitalWrite(latchPin, HIGH);
}
if (val >= 0 && val < 5)
else if (val >= 6 && val <= 10)
else if (val >= 11 && val <= 15) {
Suppose val is 5. What happens?
If val is less than 10, the 1st of second if blocks deal with that situation. The val >= 11 part is unnecessary, because val has to be greater than 10 in order to have gotten by the first two checks. The same holds true for all the other compound if tests, except the first one, where, apparently, the value of 5 is to be explicitly ignored (or not).
Here is the code, if this isn't it I'll assume I looked at a bad datasheet for my shift registers pinoutpinout.
Suppose val is 5. What happens?
If val is less than 10, the 1st of second if blocks deal with that situation. The val >= 11 part is unnecessary, because val has to be greater than 10 in order to have gotten by the first two checks. The same holds true for all the other compound if tests, except the first one, where, apparently, the value of 5 is to be explicitly ignored (or not).
This was clearly a mistake(I'm surprised you couldn't tell), but the last else statement would have caught it. I have triple checked my LEDs too.
are you sure that is otherwise the full sketch?
daniel
Yep, all hand typed, ctrl+a - ctrl+c to copy it all.