system
February 25, 2015, 3:05pm
1
Hi guys,
Please could you help me with the code for ShiftOUT registers. Is is possible to have 6 times shift out?
I have found this code, it works up to 32bits, but not more:
void registerWrite(long whichPin, int whichState) {
digitalWrite(latchPin, LOW);
if ( whichPin < 32) {
bitWrite(bitsToSend_1, whichPin, whichState);
}
else {
bitWrite(bitsToSend_2, whichPin - 32, whichState);
}
//Serial.print(whichPin);Serial.print(' ');Serial.print(bitsToSend_1,BIN); Serial.print(' ');Serial.println(bitsToSend_2,BIN);
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend_2 );
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend_1 >> 24);
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend_1 >> 16);
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend_1 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend_1 );
digitalWrite(latchPin, HIGH);
}
Thanks a lot!
Sure, add as many shiftOut()s as you need.
Where is the 6th byte of data coming from?
system
February 25, 2015, 3:26pm
3
Hi!
thanks for reply. Registers are in the queue: data goes from Arduino to DS (1st reg) than Q7' - DS ... etc
What queue?
You have a function:
void registerWrite(long whichPin, int whichState)
which you are sending 6 bytes of data: 4 in whichPin, and 2 in whichState
You seem to only shiftOut one byte of whichState, so change the code to send both:
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend_2 );
to
shiftOut(dataPin, clockPin, MSBFIRST, highByte (whichState) );
shiftOut(dataPin, clockPin, MSBFIRST, lowByte (whichState) );
I have found this code, it works up to 32bits, but not more:
How about trying to write some.
What if your mum said, "I found this pizza, we are having it for dinner", if it had not got the toppings you wanted on it what would you do.
It's rubbish code anyway, probably the same as any pizza you would "find".
system
February 25, 2015, 6:05pm
6
thanks Mike, but no help anyway have a nice day!
Try and understand what you are trying to do. That code is not a good starting point, what made you pick it?
Go to the arduino tutorial and look at that code.
Know that a long long data type is eight bytes long. Use that.